http://coldfusion.com logo
#cfwheels
Title
# cfwheels
a

Adam Cameron

03/24/2022, 5:31 PM
I wonder if I could get some clarification on the usage of
$
as a prefix to method names in CFWheels. It seems to me that this is used in lieu of actually making a method private. The only reference I have been able to find for this in the docs is a mention in passing:
If you have functions that should only be called from the plugin itself, we recommend starting the function name with the
$
character (this is how many internal Wheels functions are named as well)
(my emphasis, and that is from https://guides.cfwheels.org/docs/developing-plugins#using-a-plugin-to-add-or-alter-capabilities) I could find no other explicit explanation, but
$
is hard to google for, so this means nothing. I didn't find anything further searching for "private" or "internal" either, that said. I want code to run every time a model object is created. Normally I would put this in the constructor of the class, but for reasons that I cannot fathom, CFWheels does not call
init
when it creates an object. So that's no good. I have found
$createInstance
in
wheels.Model
, and if I override that in my own models, it seems to work as I'd expect. Certainly when I call
new
/
findOne
/
findAll
on the model factory object, it seems to be called on the returned model object(s). However I am cautious that it's a method prefixed with
$
, therefore "internal" to CFWheels. I should probably not be messing with it, or calling it directly (even in an overridden implementation of itself). So is there a more CFWheels-idiomatic way of doing this? Or am I fine with this approach? Cheers.
p

Peter Amiri

03/24/2022, 6:59 PM
@Adam Cameron could you not use the
afterInitialization()
Callback Function. https://guides.cfwheels.org/docs/object-callbacks
1
a

Adam Cameron

03/24/2022, 8:18 PM
Oooh, I'll look at that tomorrow (in the pub watching sportsball ATM). Thanks dude.
Yep that did the trick! Thanks @Peter Amiri 🙂
2 Views