|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Establishing Application-Level Settings
|
|
|
|
When any ColdFusion application page is requested, ColdFusion searches up the page's directory tree for an Application.cfm file. When it is found, the Application.cfm code is logically included at the beginning of that page.
If it is not found, ColdFusion searches up the directory tree until it finds an Application.cfm file. If more than one Application.cfm file lives in the current directory tree, ColdFusion uses the first one it finds.
|
|
|
|
Note
|
|
|
ColdFusion continues searching for the Application.cfm file up to the root directory of the hard drive where the web root resides.
|
|
|
|
Advantages of using the Application Framework |
|
|
|
Because the Application.cfm page is processed before any other application page, it gives you the ability to set application-level parameters, and to perform queries and other functions.
Since Application.cfm files are standard ColdFusion application pages, you may use CFML code within them to dynamically determine the values of application-level settings based on queries, client-state information, and so on.
By defining a scope for one or more applications, Application.cfm files can be implemented for individual or multiple applications. A single Application.cfm file, installed in your ColdFusion application root directory, can globally control settings in multiple applications nested below the root.
|
|
|
|
Note
|
|
|
ColdFusion Server scope variables are available to all application pages. This is a potential source of conflict with variables set in Application.cfm pages. See How ColdFusion looks up variables in Chapter 4, Creating and Manipulating Variables for information on the order in which ColdFusion finds variables.
The flexibility of ColdFusion allows for a number of different ways to configure ColdFusion applications. The following sections describe a basic approach that will work for most cases.
|
|
|
|
Defining an application |
|
|
|
An important step in designing a ColdFusion application is mapping out its directory structure.
Before you start building the application, establish a root directory for the application. Application pages may also be stored in sub-directories of the root directory.
|
|
|
|
Note
|
|
|
In UNIX, the references to Application.cfm are case-sensitive. The filename must be spelled with an initial capital.
|
|
|
|
To set up an application framework:
|
|
|
- Create an
Application.cfm file in the root of the application directory for application-level settings.
- Set application-level settings and error handling.
- Enable client state management with the CFAPPLICATION tag.
- Enable any optional features you want, such as security (using CFAUTHENTICATE), locking (using CFLOCK), or error handling (using CFERROR).
For details on setting up user security in the Application.cfm file, see the user security information in Advanced ColdFusion Development.
|
|
|
|
Establishing an application root directory |
|
|
|
All of the page files in an application do not need to be in the same root directory. However, defining a root directory for an application has a number of advantages:
- Development: The application is easier to develop and maintain because the application page files are well organized.
- Portability: The application can be more easily moved to another server or another part of a server without having to change any code in the application page files.
- Application-level Settings: Application pages that fall under the same root directory can share application-level settings and functions.
- Security: Application pages that fall under the same directory can share Web server security settings.
You can use a single Application.cfm file for your application, or use many different Application.cfm files that govern individual sections of the application.
|
|
|
|
Application scope example
|
|
|
The directory trees below illustrate two approaches to implementing the Application Framework.
- In the first example, a company named Web Wonders, Inc. uses a single
Application.cfm file installed in their application root directory to process all application page requests.
- The illustration on the right shows how Bandwidth Associates uses the settings in individual
Application.cfm files to specify processing for ColdFusion applications at the departmental level. Only the Products application pages are processed using the settings in the root Application.cfm file. The Consulting, Marketing, and Sales directories each has its own Application.cfm file.
|
|
|
|
Behavior with CFINCLUDE |
|
|
|
Only one Application.cfm file is ever processed for each ColdFusion application page. The presence of an Application.cfm file is an implicit CFINCLUDE. If it is present in the directory tree, there is no way not to include it. (For this reason, it is the ideal location to set application-level variables.)
When the requested application page has a CFINCLUDE tag pointing to an additional application page, ColdFusion does not initiate another search up the directory tree based on the included application page.
This is an important behavior to understand. Upon opening a requested application page, ColdFusion searches for the Application.cfm file only once.
|
|
|
  
|
|
|
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.
|