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">

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.