Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access variables from Appliction.cfc

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

like image 480
John Barrett Avatar asked Dec 26 '22 16:12

John Barrett


2 Answers

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

like image 102
Evik James Avatar answered Jan 09 '23 06:01

Evik James


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

like image 41
JamesRLamar Avatar answered Jan 09 '23 05:01

JamesRLamar