On Tue, 28 Dec 2004 11:39:22 -0500, Jeff Small <[EMAIL PROTECTED]> wrote:
> <cfset init()>
Be wary of calling functions from the pseudo-constructor - if the CFC
is accessed in any way, including the doc browser, it will execute
this and call the function. In general I recommend *not* calling
init() automatically in the CFC but requiring users of the CFC to call
init() at construction time:
<cfset obj = createObject("component","mycfc").init()/>
> <cffunction name="init" access="private" output="false" returntype="string"
> displayname="Initializes my object and creates the datasource variable">
Normally, people would expect init() to be public and return an
instance of the CFC itself:
<cffunction name="init" access="public" output="false" returntype="mycfc"
hint="Initializes my object and created the datasource variable">
> <cfset variables.DSN = "myDataSourceName">
> <cfreturn variables.DSN>
<cfreturn this/>
> </cffunction>
>
> I know I could make it so that you have to pass the datasource variable name
> in to the function, but I figured, I can always just change it in one place
> in my CFC, and it's good to go...right?
Yes, that's a reasonable argument. You could even give init() an
optional argument to allow users to override the DSN without code
changes:
<cfargument name="DSN" type="string" default="myDataSourceName"/>
<cfset variables.DSN = arguments.DSN/>
> That should suit my needs, right? If I want a variable that's available to
> all the functions in my CFC...right? Am I thinking the "right way"?
With the caveats about expectations for the init() function, yes,
you're on the right track.
--
Sean A Corfield -- http://www.corfield.org/
Team Fusebox -- http://www.fusebox.org/
Breeze Me! -- http://www.corfield.org/breezeme
Got Gmail? -- I have 6 invites to give away!
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188866
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54