Skip to main content
September 23, 2009
Answered

Passing a cfc object to another cfc

  • September 23, 2009
  • 1 reply
  • 809 views

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.



This topic has been closed for replies.
Correct answer Adam Cameron.

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

1 reply

Adam Cameron.Correct answer
Inspiring
September 23, 2009

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

September 24, 2009

Hi Adam,

Thanks for your answer.  I wasn't aware that you can just pass a CFC object just like a normal variable.

Regards,