ColdFusion 9.0 Resources |
Using an Application.cfm pageIf you do not use an Application.cfc file, use the Application.cfm page to define application-level settings and functions. Naming the applicationUse 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 optionsUse the cfapplication tag to specify client state and persistent variable use, as follows:
You can also optionally do the following:
For more information on configuring these options, see Using Persistent Data and Locking and the CFML Reference. Defining page processing settingsThe 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. Setting application default variables and constantsSet default variables and application-level constants on the Application.cfm page. For example, specify the following values:
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 loginsWhen 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 errorsUse 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 pageThe 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. ---> <cfapplication name="Products" clientmanagement="Yes" clientstorage="myCompany" sessionmanagement="Yes"> <!--- Set page processing attributes. ---> <cfsetting showDebugOutput="No"> <!--- Set custom global error handling pages for this application.---> <cferror type="request" template="requesterr.cfm" mailto="admin@company.com"> <cferror type="validation" template="validationerr.cfm"> <!--- Set the Application variables if they aren't defined. ---> <!--- Initialize local app_is_initialized flag to false. ---> <cfset app_is_initialized = False> <!--- Get a read-only lock. ---> <cflock scope="application" type="readonly" timeout=10> <!--- Read init flag and store it in local variable. ---> <cfset app_is_initialized = IsDefined("Application.initialized")> </cflock> <!--- Check the local flag. ---> <cfif not app_is_initialized> <!--- Application variables are not initialized yet. Get an exclusive lock to write scope. ---> <cflock scope="application" type="exclusive" timeout=10> <!--- Check the Application scope initialized flag since another request could have set the variables after this page released the read-only lock. ---> <cfif not IsDefined("Application.initialized")> <!--- Do initializations ---> <cfset Application.ReadOnlyData.Company = "MyCompany"> <!--- and so on ---> <!--- Set the Application scope initialization flag. ---> <cfset Application.initialized = "yes"> </cfif> </cflock> </cfif> <!--- Set a Session variable.---> <cflock timeout="20" scope="Session" type="exclusive"> <cfif not IsDefined("session.pagesHit")> <cfset session.pagesHit=1> <cfelse> <cfset session.pagesHit=session.pagesHit+1> </cfif> </cflock> <!--- Set Application-specific Variables scope variables. ---> <cfset mainpage = "default.cfm"> <cfset current_page = "#cgi.path_info#?#cgi.query_string#"> <!--- Include a file containing user-defined functions called throughout the application. ---> <cfinclude template="commonfiles/productudfs.cfm"> Reviewing the codeThe following table describes the code and its function:
|