On Thursday, Mar 27, 2003, at 18:37 US/Pacific, [EMAIL PROTECTED]
wrote:
> If I have a cfc that is nested in another cfc, is there a way to
> access the parent object's variables?
>
> I have something like this.
>
> <cfif NOT isDefined("session.user.order")>
> <cfset order = createObject("component", "cfc\order")>
> <cfset session.user.order = order>
> </cfif>
One option is to pass in the parent object reference (session.user)
when you create the order and have the order remember it:
<cfscript>
if ( not structKeyExists(session.user,"order") ) {
order = createObject("component", "cfc.order");
order.init( session.user );
session.user.order = order;
}
</cfscript>
And inside order.cfc:
<cfcomponent>
<cfset instance = structNew()/>
<cffunction name="init" returntype="void">
<cfargument name="parent" type="cfc.user"/>
<cfset instance.parent = arguments.parent/>
</cffunction>
... rest of order.cfc ...
... instance.parent is owning user ...
</cfcomponent>
A couple of things to note here:
- 'init()' matches what you do when manipulating Java objects (create,
init)
- 'init()' returns void - meaning "I return nothing"
- 'instance' is convenient way to handle non-public instance data
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4