Adam Cameron
$
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(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, butcharacter (this is how many internal Wheels functions are named as well)$
$
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.Peter Amiri
03/24/2022, 6:59 PMafterInitialization()
Callback Function. https://guides.cfwheels.org/docs/object-callbacksAdam Cameron
Adam Cameron