Processing the Application.cfm page

To not make this to difficult, try to look at application.cfm file as a global template that will automatically be included in every page in your application.
 

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.
 
 
If you try to run the application.cfm file in your browser, you will get the following error:
You have requested a page with the name application.cfm. This file name is reserved by the ColdFusion engine for the specification of application level settings and therefore cannot be directly requested from a web client.
 
 
The special application-wide page called Application.cfm defines application-level settings and functions such as:
  • Application name
  • Client state management options
  • Application and Session variable management options
  • Default variables
  • Application-specific custom error pages
  • Data sources
  • Default style settings
  • Exclusive locks
  • Other application-level constants
 
About this tutorial:
This tutorial explains the basic of the application.cfm file and the application search for the file named application.cfm in the directory structure.
 
First create a web site structure like this:

 

ColdFusion files:

app_globals.cfm (root) 

<cfset page_name = "application.cfm - Test">

 
application.cfm (root)

<cfinclude template="app_global.cfm">

<cfset my_variable = "application.cfm - [root]">

 
index.cfm (root)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title><cfoutput>#page_name#</cfoutput></title>

</head>

<body>

<div align="center"><strong>APPLICATION.CFM TEST</strong><br><br><br><a href="test.cfm">Display file test.cfm [root]</a><br>

<br>

<a href="new_dir/test.cfm">Display file test.cfm [new_dir]</a></div>

</body>

</html>

 
test.cfm (root)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title><cfoutput>#page_name#</cfoutput></title>

</head>

<body>

<div align="center"><cfoutput><strong>#page_name#</strong></cfoutput><BR><BR><BR>

</div>

Output variable(s) from application.cfm:[<cfoutput>#my_variable#</cfoutput>]<br><br><br>

<a href="index.cfm">Back to main menu</a></body>

</html>

 
application.cfm (new_dir)

<cfinclude template="../app_global.cfm">

<cfset my_variable = "application.cfm - [new_dir]">

 
test.cfm (new_dir)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title><cfoutput>#page_name#</cfoutput></title>

</head>

<body>

<div align="center"><cfoutput><strong>#page_name#</strong></cfoutput><BR><BR><BR>

</div>

Output variable(s) from application.cfm:[<cfoutput>#my_variable#</cfoutput>]<br><br><br>

<a href="../index.cfm">Back to main menu</a></body>

</html>

 
Run the index.cfm file and you see how this works. Try rename (delete) one of the application.cfm files (hint use IsDefined ) and see what's happen.
 
We will take a closer look at the application-level settings and functions later.
 

Advertisement

Radar: Subscribe & Save!

No User Comments.

No User Comments, be the first one to write your comments?

ApplayIT is owned by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.