Ok, let me see if I'm understanding this...

<cfset agentLibrary =
createObject("component","components.agents.agent").init(
datasourcename ) />

The part above goes in the calling page before the cfinvoke
statement, right?  If so, how does this work with the cfinvoke statement?
Is "agentLibrary" above becoming the variable that will hold
all the data returned by the cfc function, "agent"?

And I've always defined my db's using
<cfset dsn='datasource'>
in my application.cfm file, so if I continue doing that, then
I guess the creation of the agentLibrary variable above would be:

<cfset agentLibrary = createObject('component', 
'components.agents.agent').init(#dsn#) />
or something?

Or would defining the variable 'dsn' in my application.cfm become
an obsolete practice in the 'cfc era'???

Also, in your code below, I don't see the variable 'agentLibrary' being used
after creation (instantiation?)...so how does it fit into the cfc functionality?

Rick


> -----Original Message-----
> From: Mike Kear [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 16, 2008 1:29 AM
> To: CF-Talk
> Subject: Re: cfc question...
> 
> Ok syntax error  forgot the closing quotes.   Make that:
> 
> 
> <cfset agentLibrary = createObject("component","components.agents.agent") />
> 
> 
> And usually at the top of an object like that (if it's for the kinds
> of things i think it is) you would have an init() function    that you
> tell the component the datasource name.     That looks something like:
> 
> <!--- Constructor / initialisation --->
> <cffunction name="init" access="Public" returntype="agent"
> output="false" hint="Initialises the component">
> <cfargument name="datasourcename" required="true" type="string" />
>       <cfset variables.dsn = arguments.datasourcename />
>       <cfreturn this />
> </cffunction>
> 
> 
> It seems a bit of extra typing to have that at the top of your cfc,
> but for reasons of encapsulation (sorry for using the jargon!)  its
> best to have the cfc so that if it needs to know something you'll tell
> it, rather than have it rely on finding what it needs in application
> or session scope or something.    So if you have that init() function
> in your component, you'd instantiate it by chaining the .init() method
> when you invoke it.  ( You can chain methods one behind the other )
> 
> <cfset agentLibrary =
> createObject("component","components.agents.agent").init(
> datasourcename ) />
> 
> Throughout your cfc, wherever any function needs to run a query on the
> datasource, it will do it like so:
> 
> <cfquery name="qThisQuery" datasource="#variables.dsn#">
>    SELECT AgentID from Agents
>   WHERE  GRPOffCE = <cfqueryparam value="#officeid#"
> cfsqltype="cf_sql_varchar"/>
> </cfquery>
> 
> 
> That way you can easily reuse the component without having to need the
> datasource to exist in application scope or anywhere else for that
> matter.  The cfc needs to know the datasourcename so you tell it that
> when you instantiate the cfc.
> 
> 
> Cheers
> Mike Kear
> Windsor, NSW, Australia
> Adobe Certified Advanced ColdFusion Developer
> AFP Webworks
> http://afpwebworks.com
> ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/month
> 
> 
> 
> On Mon, Jun 16, 2008 at 3:15 PM, Mike Kear <[EMAIL PROTECTED]> wrote:
> > I think you're nearly there, Rick.    Just make sure you are following
> > the rules about how to set out paths for components:
> >
> > if your component is in
> > e:\inetpub\webroot\c21ar\components\agents\agent.cfc   and the web
> > root is at e:\inetpub\webroot\c21ar,  then you would invoke the
> > component with the following: ("Instantiate" is another term that
> > confused me at first - how is 'instantiate' different from'invoke'?
> > answer:  it's the same thing)
> >
> > <cfset agentLibrary = createObject("component","components.agents.agent) />
> >
> >
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307566
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to