Okay, since the mock code might not have the same issue, here's the
actual stuff.
<cfcomponent displayname="Collection" hint="A base collection object">
<cfset _DSN = "" />
<cfset _data = "" />
<cffunction name="init" hint="Initialize the collection:
pseudo-constructor" returntype="collection" output="no">
<cfargument name="datasource" required="Yes" type="string" />
<cfset _DSN = arguments.datasource />
<cfset _data = "" />
<cfreturn this />
</cffunction>
<cffunction name="read" hint="Obtain collection data from database"
returntype="query" output="no">
<cfif IsSimpleValue(_data)>
<cfset refresh() />
</cfif>
<cfreturn _data />
</cffunction>
<cffunction name="refresh" hint="Force re-obtain collection data from
database" returntype="collection" output="no">
<cfthrow type="interface.methodNotInherited" message="The refresh
method of the collection class must be overridden by its inheriting
classes" />
</cffunction>
<cffunction name="deleteRecord" hint="Obtain collection data from
database" returntype="collection" output="no">
<cfargument type="string" name="recordID" required="yes" />
<cfthrow type="interface.methodNotInherited" message="The read
method of the collection class must be overridden by its inheriting
classes" />
</cffunction>
</cfcomponent>
<cfcomponent displayname="User Collection" extends="collection" hint="A
collection of users">
<cffunction name="refresh" hint="Force re-obtain collection data from
database" returntype="collection" output="no">
<cfquery name="_data" datasource="#_DSN#">
SELECT *
FROM users
</cfquery>
<cfreturn this />
</cffunction>
<cffunction name="deleteRecord" hint="Obtain collection data from
database" returntype="collection" output="no">
<cfargument type="string" name="recordID" required="yes" />
<cfset var deleting = "" />
<cfquery name="deleting" datasource="#_DSN#">
DELETE
FROM users
WHERE user_id = #arguments.recordID#
</cfquery>
<cfreturn refresh() />
</cffunction>
</cfcomponent>
Framework templates:
(name-locked write if not defined)
<cfset application.collections.users =
CreateObject("component","usercollection").init(application.DSN.safeTrac
k) />
...
<cfset StructAppend(request, duplicate(application)) />
Calling template:
<cfdump var="#request.collections.users.read()#" />
Error:
Variable _data is undefined.
The error occurred in collection.cfc: line 11
Dave, thanks for taking a look at this earlier. Hopefully somebody will
help me find what I'm missing.
-----Original Message-----
From: Davis, Eric
Sadly, that was almost exactly what I had before I pulled it into the
pseudo-constructor, and it still threw the same error.
<cfcomponent displayname="base">
<cffunction name="init">
<cfset _hidden = "" />
<cfreturn this />
</cffunction>
<!--- read function --->
</cfcomponent>
<!--- child cfc exactly the same --->
<!--- calling template --->
<set obj = createObject("component", "child").init() />
<dump var="#obj.read()#" />
BZZZT - same error.
-----Original Message-----
From: David Ross
I'm guessing the pseudo-constructor area is not run for the base
component. Put that code in a function (call it init(), please), then
call super.init() upon instantiating the child component.
>>> [EMAIL PROTECTED] 7/6/2004 2:23:09 PM >>>
I'm sure I'll kick myself shortly, but after spending two weeks trying
and failing to write a cross-browser javascript webservice consumption
class and then a week on vacation in Mexico, apparently my simple CFC
skills have left me entirely. This problem has to do with the
inheritance chain and the unnamed scope. Here's a mockup of the code
I've got.
<-- base.cfc --->
<cfcomponent>
<cfset _hidden = "" />
<cffunction name="read" returntype="struct">
<cfif IsSimpleValue(_hidden)>
<cfset setValue() />
</cfif>
<cfreturn _hidden />
</cffunction>
</cfcomponent>
<-- child.cfc -->
<cfcomponent extends="base">
<cffunction name="setValue" returntype="base">
<cfset _hidden = StructNew() />
<cfset _hidden.key1 = "value1" />
<cfreturn this />
</cffunction>
</cfcomponent>
When I invoke child.cfc and try the read() method, I get an error that
says _hidden is not defined, thrown in the IsSimpleValue() check.
Why? I've defined no arguments so that collision isn't possible, and
I'm
just trying to use the unnamed scope - note that in a prior version of
similar functionality, when all of this is in one cfc, there's no
error
whatsoever.
Other components I've written use an "instance" structure in the
unnamed
scope, and work just fine. What could possibly be wrong with this
code?
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]