If you do not use an Application.cfc file, use the Application.cfm page to define application-level settings and functions.
Naming the application
Use the cfapplication tag to specify the application name and define a set of pages as part of the same logical application. Although you can create an application by placing a cfapplication tag with the application name on each page, you normally place the tag in the Application.cfm file; for example:
<cfapplication name="SearchApp"> |
Note: The value that you set for the name attribute in the cfapplication tag is limited to 64 characters. |
Setting the client, application, and session variables options
Use the cfapplication tag to specify client state and persistent variable use, as follows:
- To use Client scope variables, specify clientManagement=True.
- To use Session scope variables, specify sessionManagment=True.
You can also optionally do the following:
- Set application-specific time-outs for Application and Session scope variables. These settings override the default values set in the ColdFusion Administrator.
- Specify a storage method for Client scope variables. This setting overrides the method set in the ColdFusion Administrator.
- Specify not to use cookies on the client browser.
For more information on configuring these options, see Using Persistent Data and Locking and the CFML Reference.
Defining page processing settings
The cfsetting tag lets you specify page processing attributes that you want to apply to all pages in your application. For more information, see Setting page processing options in Defining the application and its event handlers in Application.cfc.
Setting application default variables and constants
Set default variables and application-level constants on the Application.cfm page. For example, specify the following values:
- A data source
- A domain name
- Style settings, such as fonts or colors
- Other important application-level variables
Often, an Application.cfm page uses one or more cfinclude tags to include libraries of commonly used code, such as user-defined functions, that are required on many of the application's pages.
Processing logins
When an application requires a user to log in, you typically place the cflogin tag on the Application.cfm page. For detailed information on security and creating logins, including an Application.cfm page that manages user logins, see Securing Applications
Handling errors
Use the cferror tag on your Application.cfm page to specify application-specific error-handling pages for request, validation, or exception errors, as shown in the following example. This way you include application-specific information, such as contact information or application or version identifiers, in the error message, and you display all error messages in the application in a consistent manner.
For more information on error pages and error handling, see Handling Errors.
Example: an Application.cfm page
The following example shows a sample Application.cfm file that uses several of the techniques typically used in Application.cfm pages. For the sake of simplicity, it does not show login processing; for a login example, see Securing Applications.
<!--- Set application name and enable Client and Session variables. ---> |
Reviewing the code
The following table describes the code and its function:
Code |
Description |
|
---|---|---|
|
Names the application, enables Client and Session scope variables, and sets the client variable store to the myCompany data source. |
|
|
Ensures that debugging output is not displayed, if the ColdFusion Administrator enables it. |
|
|
Specifies custom error handlers for request and validation errors encountered in the application. Specifies the mailing address for use in the request error handler. |
|
|
Sets the Application scope variables, if they are not already set. For a detailed description of the technique used to set the Application scope variables, see Using Persistent Data and Locking. |
|
|
Sets the Session scope pagesHit variable, which counts the number of pages touched in this session. If the variable does not exist, creates it; otherwise, increments it. |
|
|
Sets two Variables scope variables that are used throughout the application. Creates the current_page variable dynamically; its value varies from request to request. |
|
|
Includes a library of user-defined functions that are used in most pages in the application. |