| Contents > Developing ColdFusion MX Applications > Designing and Optimizing a ColdFusion Application > Creating the Application.cfm page > 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 --->
<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 readonly 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">
The following table describes the code and its function:
Code |
Description |
|---|---|
<cfapplication name="Products" clientmanagement="Yes" clientstorage="myCompany" sessionmanagement="Yes"> |
Names the application, enables Client and Session scope variables, and sets the client variable store to the myCompany data source. |
<cfsetting showDebugOutput="No" > |
Ensure that debugging output is not displayed, if the ColdFusion MX Administrator enables it. |
<cferror type="request" template="requesterr.cfm" mailto="admin@company.com"> <cferror type="validation" template="validationerr.cfm"> |
Specifies custom error handlers for request and validation errors encountered in the application. Specifies the mailing address for use in the request error handler. |
<cfset app_is_initialized = False> . . . |
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. |
<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>
|
Sets the Session scope |
<cfset mainpage = "default.cfm"> <cfset current_page = "#cgi.path_info#?#cgi.query_string#"> |
Sets two Variables scope variables that are used throughout the application. Creates the current_page variable dynamically; it's value varies from request to request. |
<cfinclude template= "commonfiles/productudfs.cfm"> |
Includes a library of user-defined functions that are used in most pages in the application. |
|
|
||
| Contents > Developing ColdFusion MX Applications > Designing and Optimizing a ColdFusion Application > Creating the Application.cfm page > Example: an Application.cfm page |
|
|
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/appfra21.htm
Comments
ubootnik said on Feb 27, 2004 at 4:20 PM :