From: jeby on
I am looking for advice on how to nest objected created from cfcs...

The place I have seen this sdone is in the fusebox framwork in the following:
#myFusebox.getCurrentCircuit().getAlias()#

What I would like to do is create an object called called users from a
users.cfc with methods such as listUsers() and findUser(userID)...

Ex. #users.findUser(34)#

Then from there I want to next another object (object might not be the correct
term) or set of functions that deal with the user specified such as getName()
and getEmail()...

Ex. #users.findUser(34).getName()#
Ex. #users.findUser(34).getEmail()#

Can someone explain to me how this can be done? Thanks!

From: Ian Skinner on
jeby wrote:

> Can someone explain to me how this can be done? Thanks!
>

How this is done depends largely on how the objects are related to each
other. I.E. Does one object extend (inherit) the other object creating
an is-a or parent child relationship. Or does one object contain an
instance of the other as a property|variable (composite) creting an
has-a relationship.

I'm doing some web service with complex object testing and I have just
written this simple testing code. See if it makes some sense to you.

basic.cfc
---------
<cfcomponent>
<cfproperty name="foo" type="string">
<cfproperty name="bar" type="string">

<cfscript>
this.foo = "George";
variables.bar = "Gracie";
</cfscript>

<cffunction name="getBar" access="remote" returntype="string">
<cfreturn variables.bar>
</cffunction>
</cfcomponent>

complex.cfc
-----------
<cfcomponent>
<cfproperty name="anObj" type="basic">

<cfscript>
variables.anObj = createObject("component","basic");
</cfscript>

<cffunction name="getObj" access="remote" returntype="basic">
<cfreturn variables.anObj>
</cffunction>
</cfcomponent>

index.cfm
---------
<cfscript>
complexComp = createObject("component","complex");
</cfscript>

<cfdump var="#basicComp#" expand="no">

<dl>
<dt>complexComp.getObj()</dt>
<dd><cfdump var="#complexComp.getObj()#"></dd>
<dt>complexComp.getObj().foo</dt><
dd>#complexComp.getObj().foo#</dd>
<dt>complexComp.getObj().getBar()</dt>
<dd>#complexComp.getObj().getBar()#</dd>
</dl>

From: GArlington on
On Apr 2, 5:20 pm, "jeby" <webforumsu...(a)macromedia.com> wrote:
> I am looking for advice on how to nest objected created from cfcs...
>
> The place I have seen this sdone is in the fusebox framwork in the following:
> #myFusebox.getCurrentCircuit().getAlias()#
>
> What I would like to do is create an object called called users from a
> users.cfc with methods such as listUsers() and findUser(userID)...
>
> Ex. #users.findUser(34)#
>
> Then from there I want to next another object (object might not be the correct
> term) or set of functions that deal with the user specified such as getName()
> and getEmail()...
>
> Ex. #users.findUser(34).getName()#
> Ex. #users.findUser(34).getEmail()#
>
> Can someone explain to me how this can be done? Thanks!

In order to be able to call a method like you specified above
[users.findUser(34).getName()] you will need to make sure that the
method users.findUser(34) returns an [instance of an] object defining
method getName(). It is as simple as that.
In fact the functionality above can be achieved with single object
users.cfc, it's method findUser(int userID) will need to return it's
own instance initialised with the values for that userID, obviously
you will have to define getName(), getEmail() and all other methods
you might want to use...