House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

cfcs defining datasource in application cfm

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
coldfusion.developer
02/21/2007 09:26 AM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dan Vega
02/21/2007 09:33 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dwayne Cole
02/21/2007 09:51 AM

>>   <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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dwayne Cole
02/21/2007 10:00 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dwayne Cole
02/21/2007 10:07 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
JediHomer
02/21/2007 10:15 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dwayne Cole
02/21/2007 10:23 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
JediHomer
02/21/2007 10:48 AM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Eric Haskins
02/21/2007 10:56 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dwayne Cole
02/21/2007 11:22 AM

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 -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard Kroll
02/21/2007 12:07 PM

> >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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dinner
02/21/2007 02:08 PM

> > >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.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard Kroll
02/21/2007 04:25 PM

> 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


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference