Okay, this is long, but here's some example code. Here's the dbdata 
(settings) cfc. You'd fill in "(yourdefault)" with whatever your default 
info is:
<cfcomponent displayname="DBData" hint="Creates a data access initialization 
object.">
<cfscript>
variables.dsn = "";
variables.username = "";
variables.password = "";
</cfscript>


<cffunction access="public" name="init" returntype="DBData" output="false" 
hint="Returns a complete DBdata object - defaults to....">
<cfargument name="dsn" default="(yourdefault)" required="true" 
type="string">
<cfargument name="username" default="(yourdefault)" required="true" 
type="string">
<cfargument name="password" default="(yourdefault)" required="true" 
type="string">

<cfscript>
setDSN(arguments.dsn);
setUsername(arguments.username);
setPassword(arguments.password);
</cfscript>

<cfreturn this />
</cffunction>


<cffunction name="getDSN" access="public" returntype="string" 
output="false">
<cfreturn variables.DSN/>
</cffunction>

<cffunction name="getUsername" access="public" returntype="string" 
output="false">
<cfreturn variables.userName/>
</cffunction>

<cffunction name="getPassword" access="public" returntype="string" 
output="false">
<cfreturn variables.password />
</cffunction>

<cffunction name="setDSN" access="private" returntype="void" output="false">
<cfargument name="dsn" required="true" type="string">
<cfset variables.dsn = arguments.dsn />
</cffunction>

<cffunction name="setUsername" access="private" returntype="void" 
output="false">
<cfargument name="username" required="true" type="string">
<cfset variables.username = arguments.username />
</cffunction>

<cffunction name="setPassword" access="private" returntype="void" 
output="false">
<cfargument name="password" required="true" type="string">
<cfset variables.password = arguments.password />
</cffunction>

</cfcomponent>

In an application, I'd have this code to instantiate this component, using 
the default settings:
<cfif not isdefined("application.dbdata") or isdefined("url.reset")>
<cflock scope="application" type="exclusive" timeout="10">
<cfscript>
application.dbdata = createObject("component", "yourPathToCfc.dbdata
").init();
</cfscript>
</cflock>
</cfif>

Here's an example of instantiating some other object that uses this cfc:
<cfif not isdefined("application.publication") or isdefined("url.reset")>
<cflock scope="application" type="exclusive" timeout="10">
<cfscript>
application.publication = createObject("component", "yourPath.publication
").init(application.dbdata);
</cfscript>
</cflock>
</cfif>

This is an example of an init function that requires the dbdata object
<cffunction access="public" name="init" returntype="publication" 
output="false" hint="Initializes the object.">
<cfargument name="dbdata" required="true" type="yourPath.DBData">
<cfset variables.dbdata = arguments.DBData> <!--- Technically, I should have 
a "setDBdata()" function here, but since I only ever set it in the init(), 
I'm being lazy. --->
<cfset setAllPubs()>
<cfreturn this >
</cffunction>

And, here's an example of a query in a cfc that uses it:
<cfquery name="allPubs" datasource="#variables.dbdata.getDSN()#" 
username="#variables.dbdata.getUsername()#" 
password="#variables.dbdata.getPassword()#">
SELECT *
FROM blah
</cfquery>






On 9/19/05, Will Tomlinson <[EMAIL PROTECTED]> wrote:
> 
> (So, if we had a cfc
> >that needed username, dsn, etc, we'd require that it be passed into an 
> init
> >function - the cfc doesn't know that the application scope exists.)
> >
> >Make sense?
> 
> Yes this makes good sense, but I think what would help most is if you 
> could show us some *REALLY* basic example code. We have no problem reading 
> the xml or ini into applications scope, but our question arises on the best 
> method for giving the data to the cfc. Trying to understand what Ray is 
> doing with galleon is just too complex for a couple of rookies. :) We need 
> to crawl first.
> 
> Thanks much,
> Will
> 
> 
>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:218679
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

Reply via email to