Mapping an application

When you design a ColdFusion application, you must map the directory structure. This activity is an important step in designing a ColdFusion application. Before you start building the application, you must establish a root directory for the application. You can store application pages in subdirectories of the root directory.

The following sections describe how you determine where to place your application pages and the Application.cfm and OnRequestEnd pages in a directory structure. For more information on how to define and use the Application.cfm page, see "Creating the Application.cfm page".

Processing the Application.cfm and OnRequestEnd.cfm pages

ColdFusion uses similar, but different, rules to locate and process the Application.cfm and OnRequestEnd.cfm pages.

Processing the Application.cfm page

When ColdFusion receives a request for an application page, it searches the page's directory for a file named Application.cfm. If one exists, the Application.cfm code is logically included at the beginning of that application page.

If the application page directory does not have an Application.cfm page, ColdFusion searches up the directory tree until it finds an Application.cfm page. If several directories in the directory tree have an Application.cfm page, ColdFusion uses the first page it finds. If the Application.cfm page is present in the directory tree (and has the required permissions set), you cannot prevent ColdFusion from including it.

ColdFusion processes only one Application.cfm page for each request. If a ColdFusion page has a cfinclude tag pointing to an additional ColdFusion page, ColdFusion does not search for an Application.cfm page when it includes the additional page.

If your application runs on a UNIX platform, which is case-sensitive, you must spell Application.cfm with an initial capital letter.

Processing the OnRequestEnd.cfm page

Just as the Application.cfm page runs before the code on an application page, an OnRequestEnd.cfm page runs, if it exists, after each application page in the same application.

The OnRequestEnd.cfm page must be in the same directory as the Application.cfm page ColdFusion uses for the current page. ColdFusion does not search beyond that directory, so it does not run an OnRequestEnd.cfm page that resides in another directory.

The OnRequestEnd.cfm page does not run if there is an error or an exception on the application page, or if the application page executes the cfabort or cfexit tag.

On UNIX systems, you must spell the OnRequestEnd.cfm file with the capital letters shown.

Defining the directory structure

Defining an application directory structure with an application-specific root directory has the following advantages:

When you put your application in an application-specific directory hierarchy, you can use a single Application.cfm page in the application root directory, or put different Application.cfm pages that govern individual sections of the application in different directories.

You can divide your logical web application into multiple ColdFusion applications by using multiple Application.cfm pages with different application names. Alternatively, you can use multiple Application.cfm pages that specify the same application name, but have different common code, for different subsections of your application.

The directory trees in the following figure show two approaches to implementing an application framework:

Two possible directory trees for implementing an application framework

Comments