Yessir.  You can supply any arguments you need within those parenthesis.
:)

-----Original Message-----
From: Rick Faircloth [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 17, 2008 1:39 PM
To: CF-Talk
Subject: RE: cfc question...

Thanks, Jason!  I'll work on this approach.
Seems much simpler to work with once the function
is instantiated in memory.

Here's a question:  Would I include argument variables
in a call like this?

<cfset qAgents = agentLibrary.getAgents() />

I assume the parenthesis are empty because no arguments
are involved?

However, if I wanted to get a particular agent's info:

<cfset qAgent = agentLibrary.get_agent_info( url.agentid ) />
if using a url, or
<cfset qAgent = agentLibrary.get_agent_info( form.agentid ) />
if using a form variable to id the agent.
Correct?

Rick

> -----Original Message-----
> From: Jason Durham [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 17, 2008 11:09 AM
> To: CF-Talk
> Subject: RE: cfc question...
> 
> You don't *have* to use cfinvoke.  I prefer not to.
> 
> Once you have instantiated (created an instance of it in memory) the
> object like you wrote below... you can 'invoke' any of the methods by
> calling them via the object instance name.
> 
> <!--- Instantiate agentLibrary component --->
> <cfset agentLibrary =
>
createObject("component","components.agents.agent").init(application.dsn
> ) />
> 
> <!--- Get a list of agents, hold in query object called 'qAgents' --->
> <cfset qAgents = agentLibrary.getAgents() />
> 
> <!--- Loop through agents and output their names --->
> <cfoutput query="qAgents">
>       Agent Name = DB_FIELD_AGENT_NAME <br />
> </cfoutput>
> 
> Soon you will find the answer to all of your questions regarding OOP
or
> CFCs will be "it depends".  What does your agentLibrary CFC do?  If
your
> agentLibrary CFC interacts with a database (as you have indicated),
then
> what you're doing is correct.  Set a variable to hold your DSN/DB
> credentials, and reference that variable when instantiating any
> components that have to access the DB.
> 
> 
> 
> -----Original Message-----
> From: Rick Faircloth [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 16, 2008 3:57 PM
> To: CF-Talk
> Subject: RE: cfc question...
> 
> 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:307625
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