4

I would like to know the new way of calling variables from the Application.cfc file when using the script function, which has the format of "this.something" My example:

component {

    // application variables
    this.datasource = "my DSN";

}

Now in my cfquery I want to access this. I used in the past I would use [cfset REQUEST.dataSource ="MyDSN"] in the Application.cfc, and then in my cfqrey I would say;

<cfquery name="rs_dailytip" datasource="#REQUEST.dataSource#">
My SQL
</cfquery>

My question is how to do this with the new Application.cfc where I am using "this.datasource"?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
John Barrett
  • 67
  • 1
  • 5

2 Answers2

8

To answer this specific question, you do NOT need to provide the datasource attribute. Your query should look like this:

<cfquery name='Q'>
    SQL GOES HERE
</cfquery>

THIS.datasource becomes the default datasource (as of CF9).

Evik James
  • 10,335
  • 18
  • 71
  • 122
2

@EvikJames is correct about the datasource attribute, but I believe if you want access to use other variables like APPLICATION.SUPPORT_EMAIL I would use the APPLICATION scope. Others may disagree, but that's what I do and it works fine.

JamesRLamar
  • 908
  • 1
  • 11
  • 22
  • Yes, you can use `application.variableName` but it would introduce coupling within the component. The best way would be add a method argument and pass it in that way. – AlexP Oct 15 '12 at 15:50
  • @AlexP, I'm not a CS major so I apologize for my ignorance, but could you please explain "coupling within the component" and give an example of a method argument? – JamesRLamar Oct 15 '12 at 18:18
  • 1
    I don't want to digress too far from the original question but take a look at this: http://en.wikipedia.org/wiki/Coupling_(computer_programming) and method arguments is simply passing the `application.variableName` **to** the function rather than calling it **within**. http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=UDFs_08.html – AlexP Oct 15 '12 at 19:33