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:
In the Application.cfc file, these because values in the This scope:
<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.
<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:
<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 at 11:20:01 AM EST.
CFML Referenced
<cfapplication>
<cfif>
<cffunction>
Categories
Comments
Comment made by Ben Nadel on December 26, 2006 at 5:15 PM
If anyone is interested, I have a real-world case study of this process that I did during a demo application. It talks about .cfc as well as has code samples of the before and after.
http://www.bennadel.com/index.cfm?dax=blog:361.view
Comment made by Michael Pumo on January 16, 2007 at 8:00 AM
If someone is having trouble using the UDF Library Include method we were used to in Application.cfm with the new Application.cfc then I have written an article on this which can be found at:
http://michaelpumo.com/article.cfm?id=19
It took me a long time to figure out a workaround as this wasn't very well documented.
Not sure that my article is the best but it's a start I guess.
Thanks.