Knowledgebase: ColdFusion

CFTag Application.cfc Template

Posted by on September 24 2013 05:22 PM

Below is a template application.cfc for ColdFusion sites. This is written in the classic CFTag format. This template covers many ColdFusion settings including DSN, custom tags, some basic error handling, and much more. 


**Configure to your liking**

<cfcomponent>
    <!---
        Application.cfc Settings: The settings below allow you to override global ColdFusion settings to keep configurations local to your application. This ensures you can make quick adjustments to your application configuration. Ensure you review the settings below and replace dummy information and remove settings that are not applicable to your ColdFusion application.         


        http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-750b.html
    --->     
    
    <cfset this.name                                          = "MY_UNIQUE_APPLICATION_NAME" />
    <cfset this.applicationTimeout                       = createTimeSpan(0, 1, 0, 0) />      
    <cfset this.clientManagement                        = false />
    <cfset this.clientStorage                               = "dsn_name_here" />
    <cfset this.customtagpaths                           = "C:\path1,C:\path2" />
    <cfset this.googleMapKey                             = "google_api_key" />
    <cfset this.datasource                                  = "default_query_dsn_name_here" />
    <cfset this.loginStorage                                = "cookie" />
    <cfset this.mappings['/my_custom_mapping'] = "c:\dir_to_path" />
    <cfset this.serverSideFormValidation             = true />
    <cfset this.sessionManagement                     = true />
    <cfset this.sessionTimeout                            = createTimeSpan(0, 0, 30, 0) />
    <cfset this.setClientCookies                          = true />
    <cfset this.setDomainCookies                       = false />
    <cfset this.scriptProtect                                = false />
    <cfset this.secureJSON                                 = false />
    <cfset this.secureJSONPrefix                         = "" />
    <cfset this.welcomeFileList                            = "" />
    <cfset this.smtpServerSettings                      = {server="", username="", password=""} />
    <cfset this.timeout                                       = 30 />
    <cfset this.debugipaddress                           = "" />
    <cfset this.enablerobustexception                 = false />
        
    <!---
        Application.cfc Event Callbacks: These functions are default callbacks that are invoked during regular coldfusion activity. For instance, when your application first starts up, the OnApplicationStart() method will be invoked allowing you to handle custom logic on first application startup. Ensure you review these methods to see which may be applicable to your application. It is recommended that at least the OnRequestStart() method is always defined.
        
        http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=AppEvents_01.html
    --->
 
    <cffunction name="onApplicationStart">
        <!---Handle OnApplicationStart Callback--->
        <cfreturn true />
    </cffunction>
    
    <cffunction name="onApplicationEnd">
        <!---Handle OnApplicationEnd Callback--->
        <cfargument name="ApplicationScope" required=true/>        
    </cffunction>
    
    <cffunction name="onRequestStart">
        <!---Handle OnRequestStart Callback--->
        <cfargument type="string" name="TargetPage" required=true />
        <cfinclude template="#arguments.TargetPage#" />
        <cfreturn true />
    </cffunction>
    
    <cffunction name="onRequest">
        <!---Handle OnRequest Callback--->
        <cfargument name = "targetPage" type="String" required=true/>        
    </cffunction>
    
    <cffunction name="onRequestEnd">
        <!---Handle OnRequestEnd Callback--->
        <cfargument type="String" name = "targetTemplate" required=true/>    
    </cffunction>
    
    <cffunction name="onSessionStart">
        <!---Handle OnSessionStart Callback--->
    </cffunction>

    <cffunction name="onSessionEnd">
        <!---Handle OnSessionEnd Callback--->
        <cfargument name = "SessionScope" required=true/>        
    </cffunction>

    <cffunction name="onError">
        <!---Handle OnError Callback
                Not all errors are caused by ColdFusion. You many wish to enable detailled errors as well.
                https://solutions.hostmysite.com/index.php?/Knowledgebase/Article/View/8604/0/aspnet-detailed-errors
                Uncomment the lines below to display errors--->
        <!---<cfargument name="Exception" required=true/>
               <cfargument type="String" name = "EventName" required=true/>  
               <cfdump var="#Arguments.Exception#">--->
    </cffunction>

</cfcomponent>

(8 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Copyright © 2016 HostMySite