How do I migrate from Application.cfm to Application.cfc?

One of the best new features of ColdFusion 7 is the Application.cfc file. This allows for much more control over the ColdFusion application. In general the process involves migrating settings (for example, enabling client and session management) and code that would handle various events. First lets look at settings. This <cfapplication> tag represents something you might have used in an Application.cfm file:

<cfapplication name="test" clientManangement=false sessionManagement=true>

In the Application.cfc file, these because values in the This scope:

<cfset this.name="this">
<cfset this.clientManagement=false>
<cfset this.sessionManagement=true>

Another common thing people do in Application.cfm is run code when the Application starts up. Developers typically check for the existence of a particular Application variable to determine if the code has already run.

<cfif not structKeyExists(application, "init")>
    <cfset application.dsn = "foo">
    <cfset application.init = true>
</cfif>

In the Application.cfc file, this can be done simpler. Since the Application.cfc file supports the idea of a method that runs when the application starts (amongst other events), there is no need to create a "flag" variable to mark that the code has been run. The above code can be replaced with the following method:

<cffunction name="onApplicationStart" returnType="boolean" output="false">
    <cfset application.dsn = "foo">
    <cfreturn true>
</cffunction>

For more information about migrating from Application.cfm, Adobe provides a quick guide in the Live Docs.

This question was written by Raymond Camden
It was last updated on December 26, 2006.

Categories

Application Management

Comments

comments powered by Disqus