<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simon Whatley &#187; this</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/this/feed" rel="self" type="application/rss+xml" />
	<link>http://www.simonwhatley.co.uk</link>
	<description>The opposite of every great idea is another great idea</description>
	<lastBuildDate>Wed, 02 Nov 2011 09:28:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Anatomy of the Application.cfc in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/anatomy-of-the-applicationcfc-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/anatomy-of-the-applicationcfc-in-coldfusion-8#comments</comments>
		<pubDate>Tue, 18 Mar 2008 09:03:38 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Adobe ColdFusion]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[CFC]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion Component]]></category>
		<category><![CDATA[cross-site]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[onApplicationEnd]]></category>
		<category><![CDATA[onApplicationStart]]></category>
		<category><![CDATA[onError]]></category>
		<category><![CDATA[onMissingTemplate]]></category>
		<category><![CDATA[onRequest]]></category>
		<category><![CDATA[onRequestEnd]]></category>
		<category><![CDATA[onRequestStart]]></category>
		<category><![CDATA[onSessionEnd]]></category>
		<category><![CDATA[onSessionStart]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[scopes]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[this]]></category>
		<category><![CDATA[www.domain.com]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=414</guid>
		<description><![CDATA[With the release of ColdFusion MX 7 came the introduction of the Application.cfc ColdFusion component. This component replaced the traditional Application.cfm and OnRequestEnd.cfm ColdFusion application templates. Furthermore, if Application.cfc is present, both of these templates are ignored by the application.

In addition to replacing the Application.cfm, the Application.cfc introduced a number of built in methods that handle specific events. These events, as discussed in detail below, allow for a greater control over events within the application.]]></description>
			<content:encoded><![CDATA[<p>With the release of ColdFusion MX 7 came the introduction of the Application.cfc ColdFusion component. This component replaced the traditional Application.cfm and OnRequestEnd.cfm ColdFusion application templates. Furthermore, if Application.cfc is present, both of these templates are ignored by the application.</p>
<p>In addition to replacing the Application.cfm, the Application.cfc introduced a number of built in methods that handle specific events. These events, as discussed in detail below, allow for a greater control over events within the application.</p>
<h2>Application Variables</h2>
<p>The <code>THIS</code> scope in the Application.cfc contains several built-in variables that allow you to set the properties of the application.</p>
<p>The following <code>cfscript</code> briefly outlines the variables that you can set to control the application&#8217;s behaviour.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//the application name (should be unique)</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff;">name</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;ApplicationName&quot;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//how long the application variables persist</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">applicationTimeout</span> <span style="color: #0000ff">=</span> <span style="color: #800080;">createTimeSpan</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">2</span>,<span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">0</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//define whether client variables are enabled</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">clientManagement</span> <span style="color: #0000ff">=</span> false;</span>
<span style="color: #000099;"><span style="color: #808080;">//where should we store them, if enabled?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">clientStorage</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;registry&quot;</span>; <span style="color: #808080;">//cookie||registry||datasource</span></span>
<span style="color: #000099;"><span style="color: #808080;">//define where cflogin information should persist</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">loginStorage</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;session&quot;</span>; <span style="color: #808080;">//cookie||session</span></span>
<span style="color: #000099;"><span style="color: #808080;">//define whether session variables are enabled</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">sessionManagement</span> <span style="color: #0000ff">=</span> true;</span>
<span style="color: #000099;"><span style="color: #808080;">//how long the session variables persist?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">sessionTimeout</span> <span style="color: #0000ff">=</span> <span style="color: #800080;">createTimeSpan</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">20</span>,<span style="color: #ff0000;">0</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//define whether to set cookies on the browser?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">setClientCookies</span> <span style="color: #0000ff">=</span> true;</span>
<span style="color: #000099;"><span style="color: #808080;">//should cookies be domain specific</span></span>
<span style="color: #000099;"><span style="color: #808080;">//i.e. *.domain.com or www.domain.com</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">setDomainCookies</span> <span style="color: #0000ff">=</span> false;</span>
<span style="color: #000099;"><span style="color: #808080;">//should we try to block cross-site scripting?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">scriptProtect</span> <span style="color: #0000ff">=</span> false;</span>
<span style="color: #000099;"><span style="color: #808080;">//should we secure our JSON calls?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">secureJSON</span> <span style="color: #0000ff">=</span> false;</span>
<span style="color: #000099;"><span style="color: #808080;">//use a prefix in front of JSON strings?</span></span>
<span style="color: #000099;">THIS.<span style="color: #0000ff">secureJSONPrefix</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;&quot;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//used to help ColdFusion work with missing files</span></span>
<span style="color: #000099;"><span style="color: #808080;">//and directory indexes. tells ColdFusion not to call</span></span>
<span style="color: #000099;"><span style="color: #808080;">//onMissingTemplate method.</span></span>
<span style="color: #000099;">THIS.welcomeFi<span style="color: #0000ff;">le</span>L<span style="color: #0000ff;">is</span>t <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;&quot;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//define custom coldfusion mappings.</span></span>
<span style="color: #000099;"><span style="color: #808080;">//Keys are mapping names, values are full paths</span></span>
<span style="color: #000099;">THIS.mappings <span style="color: #0000ff">=</span> <span style="color: #800080;">structNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//define a list of custom tag paths.</span></span>
<span style="color: #000099;">THIS.customTagPaths <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;&quot;</span>;</span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Method Summary</h2>
<p>Below is a brief discussion of the built-in event methods available to the Application.cfc. Since the Application.cfc is a regular ColdFusion component, you can also implement your own methods alongside the built in ones (assuming the names are uniquely different).</p>
<h3>The onApplicationStart Method</h3>
<p>Runs when the application first starts up: when the first request for a page is processed or the first <acronym title="ColdFusion Component">CFC</acronym> method is invoked by an event.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onApplicationStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000ff;">&lt;</span>cfreturn true <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method is typically used to initialise code; for example to to set variables, such as datasource, into the <code>APPLICATION</code> scope, or create <a href="http://en.wikipedia.org/wiki/Singleton_pattern" title="Singleton Design Pattern" target="_blank" rel="nofollow">Singleton</a> instances of ColdFusion components.</p>
<p>For example:</p>
<p>The following example creates structures in tha application scope to store general configuration settings and Singleton objects that can be later referenced by the application framework.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onApplicationStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// INITIALISE CONFIGURATION VARIABLES AND APPLICATION BUSINESS COMPONENTS</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// **********************************************************************</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// LOAD COMMON SITE VARIABLES INTO APPLICATION SCOPE</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// create structure to hold configuration settings</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strConfig <span style="color: #0000ff">=</span> <span style="color: #800080;">structNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #808080;">//site-wide datasource(s)</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strConfig.<span style="color: #0000ff">datasource</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;DatasourceName&quot;</span>;</span>
<span style="color: #000099;">	<span style="color: #808080;">// default records per page for pagination</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strConfig.rec<span style="color: #0000ff;">or</span>dsPerPa<span style="color: #0000ff;">ge</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">15</span>;</span>
<span style="color: #000099;">	<span style="color: #808080;">// **********************************************************************</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// LOAD PERSISTENT OBJECTS INTO APPLICATION SCOPE</span></span>
<span style="color: #000099;">	<span style="color: #808080;">// data for object instantiation</span></span>
<span style="color: #000099;">	strArgs	<span style="color: #0000ff">=</span> <span style="color: #800080;">structNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #808080;">// flush strArgs</span></span>
<span style="color: #000099;">	strArgs.<span style="color: #0000ff">datasource</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">APPLICATION</span>.strConfig.<span style="color: #0000ff">datasource</span>;</span>
&nbsp;
<span style="color: #000099;">	<span style="color: #808080;">// create structure to hold objects</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs <span style="color: #0000ff">=</span> <span style="color: #800080;">structNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs.objUserMana<span style="color: #0000ff;">ge</span>r <span style="color: #0000ff">=</span> <span style="color: #800080;">createObject</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>,<span style="color: #009900;">&quot;com.whatley.user.UserManager&quot;</span><span style="color: #000000;">&#41;</span>.init<span style="color: #000000;">&#40;</span><span style="color: #0000ff">argumentCollection</span><span style="color: #0000ff;">=</span>strArgs<span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #808080;">//etc...</span></span>
&nbsp;
<span style="color: #000099;">	<span style="color: #808080;">// instantiate utility service objects</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs.objEmailServices <span style="color: #0000ff">=</span> <span style="color: #800080;">createObject</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>,<span style="color: #009900;">&quot;com.whatley.service.Email&quot;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs.objFi<span style="color: #0000ff;">le</span>Services <span style="color: #0000ff">=</span> <span style="color: #800080;">createObject</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>,<span style="color: #009900;">&quot;com.whatley.service.File&quot;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs.objQueryServices <span style="color: #0000ff">=</span> <span style="color: #800080;">createObject</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>,<span style="color: #009900;">&quot;com.whatley.service.Query&quot;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #808080;">//etc...</span></span>
&nbsp;
<span style="color: #000099;">	<span style="color: #808080;">// native coldfusion objects</span></span>
<span style="color: #000099;">	<span style="color: #0000ff">APPLICATION</span>.strObjs.objServiceFact<span style="color: #0000ff;">or</span>y <span style="color: #0000ff">=</span> <span style="color: #800080;">createObject</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>,<span style="color: #009900;">&quot;coldfusion.server.ServiceFactory&quot;</span><span style="color: #000000;">&#41;</span>;</span>
&nbsp;
<span style="color: #000099;">	<span style="color: #808080;">// **********************************************************************</span></span>
<span style="color: #000099;">	return true;</span>
<span style="color: #000099;">	<span style="color: #800000;">&lt;/cfscript&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>Since the objects above are created as Singletons, we do not have to create or destroy objects throughout the application, but simply reference the object held in memory. This is efficient, but of course, would not be suitable for per-session objects, such as shopping carts.</p>
<p>For example:</p>
<p>Referencing and invoking an object from the <code>APPLICATION</code> scope:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfinvoke</span> <span style="color: #0000ff;">object</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;APPLICATION.strObjs.objUserManager&quot;</span> <span style="color: #0000ff;">method</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;getUser&quot;</span> <span style="color: #0000ff">returnvariable</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;qryGetUser&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;userId&quot;</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#SESSION.strUser.userId#&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cfinvoke&gt;</span></span></pre></div></div>

<h3>The onApplicationEnd Method</h3>
<p>Runs when the application stops: when the application times out or the service is stopped.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onApplicationEnd&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;applicationScope&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method is typically used to clean-up currently activities, save the current state of the application to a database or log the application&#8217;s end to a file. The latter can be useful to help determine when and why an application ended.</p>
<p>Below is a simple example of how you could implement a simple log:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onApplicationEnd&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;applicationScope&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #800000;">&lt;cflog</span> <span style="color: #0000ff">file</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#THIS.Name#&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Information&quot;</span></span>
<span style="color: #333333;">        	<span style="color: #0000ff;">text</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Application #ARGUMENTS.applicationScope.applicationName# Ended&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>Notes:</p>
<ul>
<li>The method is not associated with an individual request so you cannot use it to display data to a user.</li>
<li>If you call this method explicity, ColdFusion does not end the application, but does execute the code within the method.</li>
<li>The method can access the <code>SERVER</code> scope directly, but does not have access to the <code>SESSION</code> and <code>REQUEST</code> scopes.</li>
</ul>
<h3>The onMissingTemplate Method</h3>
<p>Triggered when the user requests a ColdFusion template that doesn&#8217;t exist.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onMissingTemplate&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;targetpage&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000ff;">&lt;</span>cfreturn true <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>ColdFusion invokes this method when it encounters a file not found condition, that is, when a URL specifies a <acronym title="ColdFusion Markup Language">CFML</acronym> page that does not exist. This is an important addition to ColdFusion 8 and allows missing template errors (also known as <a href="http://en.wikipedia.org/wiki/HTTP_404" title="HTTP 404 Error" target="_blank" rel="nofollow">HTTP 404</a> errors) to be captured more efficiently by the application framework.</p>
<h3>The onRequestStart Method</h3>
<p>Runs before the request is processed.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onRequestStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;thePage&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000ff;">&lt;</span>cfreturn true <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method is great for user authorisation and login handling and for request specific variable initialisation. For example, you could use this method to log statistics to a database (performance and usage).</p>
<p>As this method runs at the beginning of a request, we can also use it to fire other events. In the example below, I reinitialise the Application which enables me to refresh objects held in memory that may have changed during code development or release.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onRequestStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">	<span style="color: #808080;">//flush the application scope</span></span>
<span style="color: #000099;">	<span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>CGI.server_name <span style="color: #0000ff">=</span><span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;localhost&quot;</span><span style="color: #000000;">&#41;</span> || <span style="color: #000000;">&#40;</span><span style="color: #800080;">structKeyExists</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">URL</span>,<span style="color: #009900;">'refresh'</span><span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">&amp;&amp;</span> <span style="color: #800080;">structKeyExists</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">URL</span>,<span style="color: #009900;">'password'</span><span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">&amp;&amp;</span> <span style="color: #0000ff">URL</span>.<span style="color: #0000ff">password</span> <span style="color: #0000ff">=</span><span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;p455w0rd&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;">	<span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">		onApplicationStart<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	<span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;">	return true;</span>
<span style="color: #000099;">	<span style="color: #800000;">&lt;/cfscript&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<h3>The onRequest Method</h3>
<p>Runs before the request is processed, but after onRequestStart.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onRequest&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;thePage&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfinclude</span> <span style="color: #0000ff">template</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#ARGUMENTS.thePage#&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This event handler provides an optional request filter mechanism for ColdFusion page requests. Use it to intercept requests to target pages and override the default behavior of running the requested pages. You can use this method to do preprocessing that is required for all requests. Typical uses include filtering and modifying request page contents (such as removing extraneous white space), or creating a switching mechanism that determines the exact page to display based on available parameters.</p>
<h3>The onRequestEnd Method</h3>
<p>Runs at the end of the request when all pages have been processed.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #808080; background-color:#ffff80;">&lt;!--- Runs at end of request ---&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onRequestEnd&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;thePage&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method can be useful for gathering performance metrics, or for displaying dynamic footer information (although I wouldn&#8217;t generally put display code in an Application.cfc).</p>
<p>For example:</p>
<p>Log the <code>CGI</code> variables to a database table.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onRequestEnd&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff;">var</span> qryInsertStats <span style="color: #0000ff">=</span> <span style="color: #800080;">queryNew</span><span style="color: #000000;">&#40;</span><span style="color: #009900;">'tempCol'</span><span style="color: #000000;">&#41;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfquery</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;qryInsertStats&quot;</span> <span style="color: #0000ff">datasource</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#APPLICATION.strConfig.datasource#&quot;</span><span style="color: #800000;">&gt;</span></span>
	INSERT INTO tbl_site_stats (template,query_string,referer,user_agent,remote_addr,datetime)
	VALUES
	(
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#CGI.PATH_INFO#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#CGI.QUERY_STRING#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#CGI.HTTP_REFERER#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#CGI.HTTP_USER_AGENT#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#CGI.REMOTE_ADDR#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfqueryparam</span> <span style="color: #0000ff;">value</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#now()#&quot;</span> <span style="color: #0000ff">cfsqltype</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;cf_sql_datetime&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	)
	<span style="color: #333333;"><span style="color: #800000;">&lt;/cfquery&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<h3>The onError Method</h3>
<p>Triggered when an error is encountered that is not caught by a try/catch block.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #808080; background-color:#ffff80;">&lt;!--- Runs on error ---&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onError&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;exception&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;eventname&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#ARGUMENTS#&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000ff;">&lt;</span>cfab<span style="color: #0000ff;">or</span>t <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method is used to handle errors in an application-specific manner. This method overrides any error handlers that you set in the ColdFusion Administrator or in cferror tags. It does not override try/catch blocks.</p>
<p>For example:</p>
<p>The following displays a friendly, static error page to the user if it is not a development server whilst also logging the error. If the error is on development, simply dump the error to screen for debugging.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onError&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;exception&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;eventName&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfif</span> CGI.server_name <span style="color: #0000ff;">neq</span> <span style="color: #009900;">&quot;localhost&quot;</span> <span style="color: #0000ff;">and</span> CGI.server_name <span style="color: #0000ff;">neq</span> <span style="color: #009900;">&quot;127.0.0.1&quot;</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #808080; background-color:#ffff80;">&lt;!--- Live application, handle error ---&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfinclude</span> <span style="color: #0000ff">template</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;error/error.htm&quot;</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #808080; background-color:#ffff80;">&lt;!--- Log all errors. ---&gt;</span></span>
	        <span style="color: #333333;"><span style="color: #800000;">&lt;cflog</span> <span style="color: #0000ff">file</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#THIS.Name#&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;error&quot;</span></span>
<span style="color: #333333;">	            <span style="color: #0000ff;">text</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Event Name: #ARGUMENTS.Eventname#&quot;</span> <span style="color: #800000;">&gt;</span></span>
	        <span style="color: #333333;"><span style="color: #800000;">&lt;cflog</span> <span style="color: #0000ff">file</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#THIS.Name#&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;error&quot;</span></span>
<span style="color: #333333;">	            <span style="color: #0000ff;">text</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Message: #ARGUMENTS.Exception.message#&quot;</span><span style="color: #800000;">&gt;</span></span>
	        <span style="color: #333333;"><span style="color: #800000;">&lt;cflog</span> <span style="color: #0000ff">file</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#THIS.Name#&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;error&quot;</span></span>
<span style="color: #333333;">	            <span style="color: #0000ff;">text</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Root Cause Message: #ARGUMENTS.Exception.rootcause.message#&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfelse&gt;</span></span>
		<span style="color: #333333;"><span style="color: #808080; background-color:#ffff80;">&lt;!--- dump error for Staging and Development ---&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfif</span> <span style="color: #800080;">len</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">ARGUMENTS</span>.eventName<span style="color: #000000;">&#41;</span><span style="color: #800000;">&gt;</span></span>
			<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#ARGUMENTS.eventName#&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;/cfif&gt;</span></span>
		<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#ARGUMENTS.exception#&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;/cfif&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<h3>The onSessionStart Method</h3>
<p>Runs when your session starts.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onSessionStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>This method is used for initialising <code>SESSION</code>-scoped data, such as a shopping basket and application form.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onSessionStart&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">	SESSION.<span style="color: #0000ff;">start</span> <span style="color: #0000ff">=</span> <span style="color: #800080;">now</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	SESSION.strShoppingBasket <span style="color: #0000ff">=</span> <span style="color: #800080;">structNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;">	SESSION.strShoppingBasket.items <span style="color: #0000ff">=</span> <span style="color: #ff0000;">0</span>;</span>
<span style="color: #000099;">	<span style="color: #800000;">&lt;/cfscript&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<h3>The onSessionEnd Method</h3>
<p>Runs when session ends</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cffunction</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;onSessionEnd&quot;</span> <span style="color: #0000ff">returnType</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;void&quot;</span> <span style="color: #0000ff">output</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;sessionScope&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #800000;">&lt;cfargument</span> <span style="color: #0000ff;">name</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;appScope&quot;</span> <span style="color: #0000ff;">type</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000ff">required</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;false&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;/cffunction&gt;</span></span></pre></div></div>

<p>Use this method for any clean-up activities when the session ends. A session ends when the session is inactive for the session time-out period. You can, for example, save session-related data, such as shopping basket contents or whether the user has not completed an order, in a database, or do any other required processing based on the user&#8217;s status. You might also want to log the end of the session, or other session related information, to a file for diagnostic use.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Adobe Livedocs has a whole <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/AppEvents_01.html" title="Application.CFC Reference" target="_blank" rel="nofollow">section dedicated to the Application.cfc</a>.</p>
<p>I have created an <a href="http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/03/application.txt" title="Example Application.cfc Template - ColdFusion 8" target="_blank">example Application.cfc</a>, which is available for <a href="http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/03/application.txt" title="Example Application.cfc Template - ColdFusion 8" target="_blank">download</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/anatomy-of-the-applicationcfc-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Application-Based Paths in ColdFusion</title>
		<link>http://www.simonwhatley.co.uk/application-based-paths-in-coldfusion</link>
		<comments>http://www.simonwhatley.co.uk/application-based-paths-in-coldfusion#comments</comments>
		<pubDate>Fri, 14 Mar 2008 11:20:08 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[administrator]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[Application.cfc]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion Administrator]]></category>
		<category><![CDATA[out-of-the-box]]></category>
		<category><![CDATA[out-of-the-box applications]]></category>
		<category><![CDATA[pathing]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[shared hosting]]></category>
		<category><![CDATA[this]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=457</guid>
		<description><![CDATA[The THIS scope in the Application.cfc contains several built-in variables that allow you to set the properties of the application; the name, session management etc. With the release ColdFusion 8 comes the introduction of application-based pathing in the form of the <code>THIS.mappings</code> and <code>THIS.customTagPaths</code> variables.]]></description>
			<content:encoded><![CDATA[<p>The THIS scope in the Application.cfc contains several built-in variables that allow you to set the properties of the application; the name, session management etc. With the release ColdFusion 8 comes the introduction of application-based pathing in the form of the <code>THIS.mappings</code> and <code>THIS.customTagPaths</code> variables.</p>
<p>The <code>THIS.mappings</code> variable can specify a structure that contains ColdFusion mappings. These settings take precedence over the mappings defined by ColdFusion Administrator Server Settings > Mappings page for the current application. Each structure element consists of the logical path as the key and the absolute path as the value. To use this variable, you must set the Enable Per Application Settings option on the ColdFusion Administrator Server Settings > Settings page.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> THIS.mappings<span style="color: #000000;">&#91;</span><span style="color: #009900;">'/com'</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;C:\Inetpub\com&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>This is syntactically equivalent to using the <code>structInsert()</code> function:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #800080;">structInsert</span><span style="color: #000000;">&#40;</span>THIS.mappings, <span style="color: #009900;">'/com'</span>, <span style="color: #009900;">'C:\Inetpub\com'</span><span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The <code>THIS.customTagPaths</code> variable can specify a list that contains ColdFusion custom tag paths. These settings take precedence over the custom tag paths defined by the ColdFusion Administrator Server Settings > Mappings page for the current application. To use this variable, you must set the Enable Per Application Settings option on the ColdFusion Administrator Server Settings > Settings page.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> THIS.customTagPaths <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;C:\Inetpub\wwwroot\myAppOne\customTags&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>Since we can specify a list, this is also valid:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> THIS.customTagPaths <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;C:\Inetpub\wwwroot\myAppOne\customTags,C:\Inetpub\wwwroot\myAppTwo\customTags&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>Alternatively, we could represent the list as:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> THIS.customTagPaths <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;C:\Inetpub\wwwroot\myAppOne\customTags&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> THIS.customTagPaths <span style="color: #0000ff">=</span> <span style="color: #800080;">listAppend</span><span style="color: #000000;">&#40;</span>THIS.customTagPaths, <span style="color: #009900;">&quot;C:\Inetpub\wwwroot\myAppTwo\customTags&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>For a long time, ColdFusion developers have needed the ability to define application-level settings actually in the application itself. These two new application-based pathing variables bring the ColdFusion developer a step closer to being able to produce out-of-the-box applications that can install in shared environments with little fuss and, more importantly, without the need to access the ColdFusion Adminsitrator to create the necessary mappings and custom tag paths.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/application-based-paths-in-coldfusion/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

