I have to maintain a variable in my Application.(cfm|cfc) to set the environment which the application currently runs under, the environment being (development|test|production).
I'd like to set an environment variable on the server itself, so that I can read its value in the Application.cfm.
Is that possible?
To set a ColdFusion variable, use the <cfset> tag. To output the variable, you need to surround the variable name with hash ( # ) symbols and enclose it within <cfoutput> tags.
The Application. cfc file defines application-wide settings and variables, and application event handlers: Application-wide settings and variables include page processing settings, default variables, data sources, style settings, and other application-level constants.
Easiest is to set a OS environment variable (at the system level, or for the user ColdFusion runs under), and restart the service. The variable is then available in the CGI scope:
<cfset EnvName = CGI.COLDFUSION_ENVIRONMENT>
<cfoutput>#EnvName#</cfoutput>
You could also use Java system properties. In your ColdFusion Administrator, go to "Server Settings/Java and JVM", and add something like this to the "JVM Arguments":
-Dcom.mycompany.environment=development
You can then ask for that value in ColdFusion:
<cfset System = CreateObject("java", "java.lang.System")>
<cfset EnvName = System.getProperty("com.mycompany.environment")>
<cfoutput>#EnvName#</cfoutput>
You would have to restart the CF Service every time you make a change, but the value seems pretty static so this should not be a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With