> Is it possible to invoke the whole component with the database  
> information and then call that instance without the dns??

Yep - it's exactly what you should be doing!

This example is simplified (normally, I'd use a CFC to represent a  
datasource instead of using the raw string datasource name.  It shows  
a CFC ("Meals") that has a "constructor" function named "init" that  
takes all of the configuration data for the CFC instance.  This is a  
common practice in the land of OO ColdFusion, as it matches how  
ColdFusion constructs Java objects.  After a Meals instance is  
constructed, all of its functions can then just use the variables.dsn  
property.

Meals.cfc:

<cfcomponent>

<cffunction name="init" hint="Constructor">
        <cfargument name="dsn" />

        <!--- Set "dsn" to the variables scope, so that it's usable by other  
functions in this CFC. --->
        <cfset variables.dsn = arguments.dsn />

        <!--- Return "this" to send back the built version of this component  
--->
        <cfreturn this />
</cffunction>

<cffunction name="getMeal">

        <cfset var myQuery = "" />

        <!--- Now, use the stored DSN --->
        <cfquery datasource="#variables.dsn#" name="myQuery">
                SELECT foo FROM bar
        </cfquery>

        <cfreturn myQuery />
</cffunction>

</cfcomponent>

Calling code:

<!--- Create an instance of Meals.  You could create one instance in  
the application scope, shared by all requests! --->
<cfset meals = createObject("component", "cfc.Meals").init 
(application.dsn) />

<cfdump var="#meals.getMeal()#" />

Hope this helps,

Joe

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:291192
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to