Joe,

Let's give you a few  concrete examples

Here is a getter and setter for an object called SubscriberGateway that
lives inside a Model-Glue controller. The MG controller is a CFC.

   <cffunction name="setSubscriberGateway" access="public"
returntype="void" output="false">
       <cfargument name="SubscriberGateway" required="true">
       <cfset variables.SubscriberGateway = arguments.SubscriberGateway />
   </cffunction>

   <cffunction name="getSubscriberGateway" access="private" output="false">
       <cfreturn variables.SubscriberGateway />
   </cffunction>

When the controller is instantiated, setSubscriberGateway() is called and an
instance of SubscriberGateway is passed into the controller. (Actually it's
just a reference, a pointer to the variable in memory, that gets passed, so
the controller doesn't get any bigger or anything like that ... the only
thing that happens is it is now allowed to use the variable that represents
the CFC instance.)

Then say i have a method in SubscriberGateway to find the active subscribers
...

<cffunction name="findActiveSubscribers" access="public" output="false"
returntype="query">
       <cfset qActiveSubscribers = "" />
       <cfquery name="qActiveSubscribers" datasource="#variables.dsn#"
username="#variables.dsu#" password="#variables.dsp#">
           select subscriberID, name, email
           from subscriber
           where isConfirmed = 1
           and isSubscribed = 1
       </cfquery>
       <cfreturn qActiveSubscribers />
   </cffunction>

and i want to use this method inside my controller. Here's what it looks
like ...

   <cffunction name="someMethod" access="public" output="false"
returntype="void">
      <cfset var qActiveSubscribers =
getSubscriberGateway().findActiveSubscribers() />
     .......

   </cffunction>

Using the var keyword, i've set this variable as local to the function only.
If i wanted to have it available throughout the CFC, i'd set it in the
variables scope.

<cfset variables.qActiveSubscribers =
getSubscriberGateway().findActiveSubscribers() />

Var scoping your local variables is very important. Remember to do it,
always.

nando


You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Reply via email to