Access Variables from Appliction.cfc

I would like to know a new way to call variables from the Application.cfc file when using a script function that has the format "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 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 use "this.datasource"?

+4
source share
2 answers

To answer this specific question, you do not need to provide a datasource attribute. Your request should look like this:

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

THIS.datasource becomes the default data source (with CF9).

+8
source

@EvikJames correctly refers to the datasource attribute, but I believe that if you want to access other variables, like APPLICATION.SUPPORT_EMAIL, I would use the APPLICATION scope. Others may disagree, but what I do and everything works fine.

+2
source

Source: https://habr.com/ru/post/1439840/


All Articles