Using an Application.cfc configuration file offers some advantages over the older style Application.cfm configuration files. Some of the main features that an Application.cfc file give you are "functions triggered by Application, Session, Request, and Error events" and "Application-Level Mappings and Custom Tag Paths".

There are only a few steps required to convert an application to use an Application.cfc file:

NOTE: You should ensure that you have a backup of any files before making changes to them.

  1. Create an "application.cfc" file

    Below is an example Application.cfc file with the minimum requirements:
    Code:
    <cfcomponent>
    	<cfscript>
    		this.name = hash( getCurrentTemplatePath() ); // unique app name
    	</cfscript>
    </cfcomponent>
  2. Setup "onRequestStart" function in "Application.cfc" to include the "Application.cfm" file

    This step is only necessary if an Application.cfm file already exists in the root of the application. Below is what the Application.cfc file will look like after this addition:
    Code:
    <cfcomponent>
    	<cfscript>
    		this.name = hash( getCurrentTemplatePath() ); // unique app name
    	</cfscript>
    
    	<cffunction name="onRequestStart"> 
    		<cfargument name="requestname" required=true />
    		<cfscript>
    			include "Application.cfm";
    			return true;
    		</cfscript>
    	</cffunction>
    </cfcomponent>
  3. Copy application settings from the "cfapplication" tag and removed the "cfapplication" tag

    This step is only necessary if a cfapplication tag is used within the application. Each attribute of the cfapplication tag will need to be copied into the cfscript section at the top of the Application.cfc with the pattern [this.attributeName = "value";].

    For example. The below cfapplication tag would be converted into our Application.cfc example as follows:

    cfapplication tag:
    Code:
    <cfapplication
    	name = "my_app_name"
    	sessionManagement = "Yes"
    	sessionTimeout = "#createTimeSpan(0,0,20,0)#"
    	setClientCookies = "Yes">
    Application.cfc:

    Code:
    <cfcomponent>
    	<cfscript>
    		this.name = "my_app_name"; // app name from old cfapplication tag
    		this.sessionManagement = "Yes";
    		this.sessionTimeout = CreateTimeSpan(0,0,20,0);
    		this.setClientCookies = "Yes";
    	</cfscript>
    
    	<cffunction name="onRequestStart"> 
    		<cfargument name="requestname" required=true />
    		<cfscript>
    			include "Application.cfm";
    			return true;
    		</cfscript>
    	</cffunction>
    </cfcomponent>
    NOTE: Do not forget to remove the "cfapplication" tag after copying the settings into the "Application.cfc" file.



Now that the change is complete, this is a good time to test the application to ensure everything is working correctly with the new setup.