(ColdFusion 9 on Win7 btw)…
I understand that all code outside a method in the application.cfc (app.cfc) is run on each and every call. I understand that the THIS.MAPPINGS structure needs to be defined outside the methods as well. However in my current mindset, my app.cfc determines first off whether the application scope exists via:
<cfif isDefined( 'application' )> ... <cfelse> ... </cfif>
If it is not defined, I assume this is the first request of the application before it is initialized and I only setup the bare minimum configs for the application to continue safely (THIS.NAME is set and I set a default CFSETTING processing directive).
The problem is, that CF will continue onto onApplicationStart (oAS) as expected, at which point I read in the config file settings from an INI file and set variables into the application scope. 2 areas of these settings are what is giving me an issue. I allow the config.ini to specify the application’s variables (appVars) and the mappings as well. So once the oAS is processed, I have keys in the application like:
application.appVar.sessionManagement=true application.appVar.sessionTimeout=createTimeSpan(0,0,30,0) ... application.mapping.www="c:\\inetpub\\wwwroot\\project\\www"
As you might have guessed, the application.appVar values coincide with out-of-oAS THIS-scope variables you would normally set before getting into the oAS. Same deal with the application.mapping variables. The ‘www’ key would invariably become a:
<cfset this.mappings["/www"]="c:\\inetpub\\wwwroot\\project\\www" />
Thing is, you can’t set THIS scope in the oAS.
PROPOSED SOLUTION: Re-request the current URL after the oAS runs
Doing so would ensure that the app.cfc gets run again, at which time, the check for the application’s existence will prove true and code in there will parse through the application.appVars and application.mappings structures and create the needed THIS scope coding outside of any methods. The thing is, to my knowledge, if you put a <cflocation> command before the <cfreturn true /> in the oAS to re-request the URL, the application will never start because it never reached the <cfreturn true /> code.
Does anyone have a recommendation that doesn’t involve manually coding the THIS scope information into the app.cfc (because it needs to stay in the config.ini file)