Making Your Application PortableH2 P class

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
Step 8.  ColdFusion Application Framework


The OnRequestEnd.cfm Template

The other special template is the OnRequestEnd.cfm template. It functions in much the same manner as the Application.cfm template with a couple of exceptions.

The first exception is that, as the name implies, the OnRequestEnd.cfm template is attached to the bottom of the requested page rather than the top.

The second exception deals with the manner in which ColdFusion searches for this template. ColdFusion Server looks for an OnRequestEnd.cfm page in the same directory where it found the Application.cfm template that it uses, not necessarily the directory where the requested page is located.

Using the directory structure shown in Figure 8.6, if we were to request the AboutUs.cfm page, we would use the Application.cfm file in the root directory. Because there is no OnRequestEnd.cfm file in this directory, however, none would be attached to the request response. If we called the Technology\Admin\Search.cfm page, we would be using the Application.cfm and OnRequestEnd.cfm files in the Admin directory. However, if we requested the Sales\Report.cfm page, it is a different story. Because there is no Application.cfm file in the Sales directory, ColdFusion Server would step up one level in the directory tree and search again. It would then find the root-level Application.cfm and use that. Next it would look for an OnRequestEnd.cfm in the same directory where it found the Application.cfm file (in this case, the root directory) and not find one. The OnRequestEnd.cfm file in the Sales directory will be completely ignored. To use this OnRequestEnd.cfm file, we have to either move it to the root directory or add an Application.cfm file to the Sales directory.

Figure 8.6. An OnRequestEnd.cfm sample directory structure.

graphics/08fig06.gif

Making Your Application Portable

The Application.cfm file can be a very powerful one. Many developers use this file to define as many Application variables as possible. Putting as many variable values and application settings as possible into the Application.cfm file makes your application much more portable.

For example, imagine this very common scenario. You are the company's ColdFusion guru, and you have developed a super groovy intranet web application for company employees to use. The site has grown to include hundreds of pages and dozens of queries. The IT department is upgrading some servers, and you are forced to move the application onto another server. In the course of this reshuffle, you will be forced to use a different data source name. Now you have to trawl through hundreds of pages to find out which ones use queries. You then have to change the data source name in each and every one of the dozens of queries, a painful exercise.

Now imagine that when you began this application, you knew about the virtues of the Application.cfm file, and you included the following line of code there:

 <CFSET MyAppDSN="Staff">

From then on, whenever you wrote each query, you used the variable in place of the usual data source name, as follows:

 <CFQUERY NAME="qStaffList" DATASOURCE="#MyAppDSN#">        SELECT  *        FROM    Employees  </CFQUERY>

Because the Application.cfm file gets included at the top of every request, each page should know the value of the #MyAppDSN# variable. Now, when you need to change the data source for your hundreds of pages and dozens of queries, you simply open your Application.cfm file and change the value of the #MyAppDSN# variable in that one line of codeand you're done.

By packing as many settings into the Application.cfm file as possible, it also makes it easy to send your application to a branch office. They could put the files on their server, simply open the Application.cfm file, change the settings to match their own environment, andpresto!be up and running.

All your settings are in one place, are easy to keep track of, and are easy to change. Beautiful.


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net