Example 8.1: Creating an Application.cfm File

Team-Fly    

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


In this example, we are going to create an Application.cfm file. We will then set a variable in the Application.cfm file and use that variable in another template.

  1. Open your text editor and type the code in Listing 8.1 or open the completed Application.cfm file from the CompletedFiles\Examples\Step08 folder.

    Listing 8.1 Application.cfm
     <!--- File:             Application.cfm  Description:      Settings for MyCompanyApp application  Author:  Created:  --->  <!--- Name application, enable session management and          set session time out to 15 minutes --->  <CFAPPLICATION NAME="MyCompanyApp"                 SESSIONMANAGEMENT="Yes"                 SESSIONTIMEOUT="#CreateTimeSpan(0,0,15,0)#">  <!--- Set the DSN to be used in this application --->  <CFSET MyAppDSN="Staff">

  2. Save this file as Application.cfm in your Examples\Step08 folder.

  3. In your Examples\Step08 folder, you will find a file called EmployeeList.cfm. This is the same file we created in Step 3, "Databases and SQL," to list all employees in the staff database.

  4. With your text editor, open the EmployeeList.cfm file from the Examples\Step08 folder.

  5. We want to use the new MyAppDSN variable that we just defined in the Application.cfm file. Find the query at the top of the EmployeeList.cfm template and replace the "Staff" text in the <CFQUERY> tag with "#MyAppDSN#", as follows:

     <!--- retrieve all employees and extensions          using the new variable set in Application.cfm--->  <CFQUERY NAME="qStaffList" DATASOURCE="#MyAppDSN#">        SELECT      FirstName, LastName, Extension        FROM        Employees        ORDER BY    LastName  </CFQUERY>
  6. Save the file and browse to it using your browser. You should get the same employee listing from Step 3, but by using a variable for our DSN instead of typing it in each time, we have made our application much more portable.


    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