I used to do it this way then I had this "bright" idea to just extend a CFC that had a whole slew of application specific values/settings that I needed. Then after realizing that was not so bright of an idea, seemed good on paper, I went back to this. The only thing I do different is I have a private method named RaiseInit that basically just checks to make sure that the object has been initiated before running any of the methods. I have that private method for when others use the objects and are not all that familiar with using them and the need to initialize them.
On 10/16/07, Joe Rinehart <[EMAIL PROTECTED]> wrote: > > > 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()#" /> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:291193 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4