Copy link to clipboard
Copied
Hi,
I am relatively new to using cfc, so I am not sure if what I am asking for is possible:
Can I pass a CFC object (that has been instantiated) to another CFC? For example, I instantiate a CFC object
<cfobject component="CFC1" name="myCFC1Obj">
<cfset myCFC1Obj.init('abc')>
Now I want to instantiate a second CFC object
<cfobject component="CFC2" name="myCFC2Obj">
I would like the functions in myCFC2Obj to have access to myCFC1Obj variables
and functions, either by passing myCFC1Obj as a function argument or by
using myCFC1Obj to instantiate myCFC2Obj.
I have read http://forums.adobe.com/message/1894989#1894989, but this
deals with instantiating CFC1 object inside CFC2. What I want is to instantiate
CFC1 object outside and pass it to CFC2.
Would I be able to do this?
Thank you.
An CFC instance (object) is just a variable like any other variable. So there's no trick to passing it into a function as an argument, you just do it as you would with any other value.
In your <cfargument> tag, if you're wont to specify the TYPE attribute, it needs to be the CFC name or path (I use path). That's the only real special consideration.
--
Adam
Copy link to clipboard
Copied
An CFC instance (object) is just a variable like any other variable. So there's no trick to passing it into a function as an argument, you just do it as you would with any other value.
In your <cfargument> tag, if you're wont to specify the TYPE attribute, it needs to be the CFC name or path (I use path). That's the only real special consideration.
--
Adam
Copy link to clipboard
Copied
Hi Adam,
Thanks for your answer. I wasn't aware that you can just pass a CFC object just like a normal variable.
Regards,