• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Step 8. ColdFusion Application Framework > Example 8.1: Creating an Application...

Example 8.1: Creating an Application.cfm File

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint