In addition to my original post below, I have a question about the
instance scope. What is it and should I be using it? I have a CFC
below that I've been using as a model for building my own CFC's.
Unfortuneately it's the only place where I've seen the instance scope
and I haven't seen it anywhere else with all of the reading I've been doing.
<cfcomponent displayname="Member Qualifiers">
<cfproperty name="id" type="numeric" default="0">
<cfproperty name="name" type="string">
<cfproperty name="email" type="string">
<cffunction name="init" access="public" output="false"
returntype="struct">
<cfargument name="aid" type="numeric" default="0">
<cfscript>
instance = structNew();
instance.id = id;
instance.name = "";
</cfscript>
<cfif instance.aid neq 0>
<cfquery name="member" maxrows="1" datasource="mp2">
select *
from members
where id = <cfqueryparam value="#arguments.id#"
cfsqltype="cf_sql_integer">
</cfquery>
<cfif member.recordcount eq 1>
<cfscript>
instance.aid = member.m_aid;
instance.old_id = member.m_old_id;
instance.company_description =
member.m_company_description;
</cfscript>
</cfif>
</cfif>
<cfreturn this>
</cffunction>
<cffunction name="get" access="public" output="false"
returntype="struct">
<cfargument name="aid" type="numeric" required="true">
<cfif not isDefined("instance")>
<cfset this.init(arguments.aid)>
</cfif>
<cfreturn instance>
</cffunction>
<cffunction name="update" access="public" output="false"
returntype="boolean">
<cfquery name="member_update" datasource="mp2">
update members
set name = <cfqueryparam value="#instance.name#"
cfsqltype="cf_sql_varchar">,
email = <cfqueryparam value="#instance.email#"
cfsqltype="cf_sql_varchar">
where id = <cfqueryparam value="#instance.id#"
cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn true>
</cffunction>
<!---
...
The complete component would also have create and delete methods
...
--->
</cfcomponent>
Mark Kecko
Technology Director
MediaPost Communications
[EMAIL PROTECTED]
212-204-2002
Mark Kecko wrote:
> Thanks to this list, Sean Corfield, Ben Forta, Hal Helms and the rest of
> the FB/CF community I'm starting to get my hands dirty using CFC's in my
> FB apps. I'm not sure if the problem below is due to my lack of
> understanding of CFC's or OO in general. Maybe you can help.
>
> In my fb4.1 circuit file I have something like:
>
> <invoke class="member" methodcall="get(url.memberid)"
> returnVariable="myMember" />
>
> Now, I know I can do:
>
> <instantiate class="member" object="aMember">
> <invoke object="aMember" methodcall="get(url.memberid)"
> returnVariable="myMember" />
>
> and this should accomplish the same thing. I also read BF's article on
> using CFC's where he says to initialize the CFC only once and then test
> to see if it was initalized on subsequent method calls. What I'm
> confused about is if I have to initialize the CFC for each user or only
> once for the 50 concurrent members I may have on my site at one time.
> That is, can I just use instantiate or cfobject in my fusebox.init file,
> create it once, and then do method calls to grab data for any user
> currently on the site or do I have to instantiate a member object for
> each user separately?
>
> I'm trying to avoid using the session scope. Right now each user has a
> two cookies with their id and login status which I use to mimic a
> session state. Would there be any difference in the way I should handle
> this if I was using the session scope?
>
>
> Mark Kecko
> Technology Director
> MediaPost Communications
> [EMAIL PROTECTED]
> 212-204-2002
>
> Sean Corfield wrote:
>
>> On Apr 11, 2005 2:42 PM, Mark Kecko <[EMAIL PROTECTED]> wrote:
>>
>>> Ok, that makes perfect sense, doh, and now I have a new error:
>>
>>
>>
>> Yeah, I got the syntax slightly wrong.
>>
>>
>>> <classes>
>>> <class alias="member" type="component"
>>> classpath="membermanager.model.member" />
>>> </classes>
>>
>>
>>
>> Yes, you need that and then change the <invoke> to refer to the
>> *alias* not the component type:
>>
>> <invoke class="member" methodcall="get(url.memberid)"
>> returnVariable="member" />
>>
>> Sorry 'bout that!
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:12:6727
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/12
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:12
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.12
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54