Initializing Application Variables

Application variables are persistent. That simply means that once you create them, they stick around. Because of this, there is no reason to set them on every request. Once you create an Application variable, you don’t need to create it. Once simple way to handle that would be with the isDefined() function.

<cfif not isDefined("APPLICATION.dsn")>
  <cfset APPLICATION.dsn = "ows">
</cfif>

This code will check to see if the variable, APPLICATION.dsn exists. If it doesn’t, it will create it. However, the Application.cfc component provides an even easier way to do this. One of the special methods mention in Table 19.1 is the onApplicationStart() method. This method will execute only when the application starts. Conversely, ...

Get Adobe ColdFusion 8 Web Application Construction Kit, Volume 1: Getting Started now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.