|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
cfcs defining datasource in application cfm
If I define a datasource variable in the application.cfm file in my webrootcoldfusion.developer 02/21/07 09:26 A This is not an attempt to promote my work but I just posted an article aboutDan Vega 02/21/07 09:33 A >> <cfquery datasource="datasource" name="Expedition">Dwayne Cole 02/21/07 09:51 A Great article. I wrap everything, almost everything, in functions and i have consistently found myself locked in. I wish I would have read this some time ago.Dwayne Cole 02/21/07 10:00 A The artcile still does not address what I think is the root of the question though.Dwayne Cole 02/21/07 10:07 A Yes they are available, however they do need to be in the ApplicationJediHomer 02/21/07 10:15 A what about request scoped variables? Are they available inside components?Dwayne Cole 02/21/07 10:23 A As far as I know these are also available, within theory you should beJediHomer 02/21/07 10:48 A Not to Hijack but I always do thisEric Haskins 02/21/07 10:56 A Eric if I was not comitted, I would use your approach. It doesn't cost much and i think it's just alot easier to back out of.Dwayne Cole 02/21/07 11:22 A > >Passing the dsn to the CFC in the create object?? Is this correct orRichard Kroll 02/21/07 12:07 P > > >Passing the dsn to the CFC in the create object?? Is this correct orDinner 02/21/07 02:08 P > Sorta off topic, but this is one area where ColdSpring is prettyRichard Kroll 02/21/07 04:25 P If I define a datasource variable in the application.cfm file in my webroot shouldn't that variable be available to a cfc inside my webroot/components/ directory? in webroot /application.cfm <CFSET datasource = "database_01"> in webroot/components/some.cfc <!--- CFC forLa Dolce/Sting contest - ---> <cffunction name="Expedition" access="public" returntype="query" output="false"> <cfquery datasource="datasource" name="Expedition"> SELECT ID FROM tbl_Ecotourism </cfquery> <cfreturn Expedition> </cffunction> ERROR IM GETTING The following information is meant for the website developer for debugging purposes. Error Occurred While Processing Request Data source datasource could not be found. This is not an attempt to promote my work but I just posted an article about this a couple of days ago that I think you would benefit from. http://www.danvega.org/blog/index.cfm/2007/2/19/Avoid-Global-Data Dan Vega http://www.danvega.org/blog/ On 2/21/07, coldfusion.developer@att.net <coldfusion.developer@att.net> wrote: ----- Excess quoted text cut - see Original Post for more ----- >> <cfquery datasource="datasource" name="Expedition"> >> SELECT ID >> FROM tbl_Ecotourism >> </cfquery> You might want to try this In the application file try this: <CFSET request.datasource = "database_01"> In the cfc try this: <cfquery datasource="#request.datasource#" name="Expedition"> You did not include the # signs around the variable name. Thats part of the problem. Reply-To: cf-talk@houseoffusion.com Date: Wed, 21 Feb 2007 09:31:55 -0500 ----- Excess quoted text cut - see Original Post for more ----- Great article. I wrap everything, almost everything, in functions and i have consistently found myself locked in. I wish I would have read this some time ago. Take this advise seriously, especially if your application architecture uses this type of structure often. Reply-To: cf-talk@houseoffusion.com Date: Wed, 21 Feb 2007 09:31:55 -0500 ----- Excess quoted text cut - see Original Post for more ----- The artcile still does not address what I think is the root of the question though. Are application variables availble inside a component (cfc) initiated within that application root? Reply-To: cf-talk@houseoffusion.com Date: Wed, 21 Feb 2007 09:31:55 -0500 ----- Excess quoted text cut - see Original Post for more ----- Yes they are available, however they do need to be in the Application scope, the initial post was just creating global variables which are not available to the CFC rather than Application variables. Similarly as someone has pointed out, the use of the variable was not surrounded with hashes so the literal word datasource was being used rather than the value of datasource HTH ----- Excess quoted text cut - see Original Post for more ----- what about request scoped variables? Are they available inside components? Reply-To: cf-talk@houseoffusion.com Date: Wed, 21 Feb 2007 15:13:28 +0000 ----- Excess quoted text cut - see Original Post for more ----- As far as I know these are also available, within theory you should be able to access Application, Session, Request and Client scopes directly, whether this is a good idea or not isn't my call ;) HTH ----- Excess quoted text cut - see Original Post for more ----- Not to Hijack but I always do this // instantiate Image CFC imgObject = CreateObject("component", "model.image").init(dsn); <cffunction name="init" returntype="user" access="public" output="false"> <cfargument name="dsn" type="string" required="yes" /> <cfset variables.dsn = arguments.dsn /> <cfreturn this /> </cffunction> Passing the dsn to the CFC in the create object?? Is this correct or should I change my ways? Always looking to better my skill Eric ----- Excess quoted text cut - see Original Post for more ----- Eric if I was not comitted, I would use your approach. It doesn't cost much and i think it's just alot easier to back out of. However, everything depends of the scope and the size of your project. My son's toy boat works fine in the bath tub but in the open ocean, we might have a few problems. Likewise I don't think a cruise ship will go over well with my wife, at least not as a toy for the kids. I think is has something to do with coupling or decoupling or something like that. Reply-To: cf-talk@houseoffusion.com Date: Wed, 21 Feb 2007 10:54:55 -0500 ----- Excess quoted text cut - see Original Post for more ----- > >Passing the dsn to the CFC in the create object?? Is this correct or > should > >I change my ways? I think it depends on your requirements and personal taste. I have done exactly the same thing, but now I also need to pass not just the DSN but also the database I'm currently working on. I chose to create a Datasource component and call Datasource.getDSN() and Datasource.getDatabase(). This way I only have to pass that as one argument and only one place to change if I ever need to. Rich Kroll > > >Passing the dsn to the CFC in the create object?? Is this correct or > > should > > >I change my ways? Sorta off topic, but this is one area where ColdSpring is pretty awesome. That's pretty much the only way I'm using CS right now-- Haven't even scratched the surface of "Advice", which is just freaking cool. > Sorta off topic, but this is one area where ColdSpring is pretty awesome. > > That's pretty much the only way I'm using CS right now-- Haven't even > scratched the surface of "Advice", which is just freaking cool. I agree completely! Rich Kroll
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||