Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a server-wide variable in ColdFusion

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?

like image 358
noobsaibot Avatar asked Jul 23 '09 07:07

noobsaibot


People also ask

How do you display a variable in ColdFusion?

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.

What is application CFC?

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.


1 Answers

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.

like image 149
Tomalak Avatar answered Sep 28 '22 07:09

Tomalak