Knowledgebase: ColdFusion

CFScript Application.cfc Template

Posted by on September 24 2013 05:14 PM

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


**Configure to your liking**

component name="MY_UNIQUE_APPLICATION_NAME" output="true"
{
    /**********************************************
        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
    **********************************************/

    this.name                                         = "MY_UNIQUE_APPLICATION_NAME";
    this.applicationTimeout                      = createTimeSpan(0, 1, 0, 0);       
    this.clientManagement                        = false;
    this.clientStorage                               = "dsn_name_here";
    this.customtagpaths                           = "C:\path1,C:\path2";
    this.googleMapKey                             = "google_api_key";
    this.datasource                                  = "default_query_dsn_name_here";   
    this.loginStorage                                = "cookie";
    this.mappings['/my_custom_mapping'] = "c:\dir_to_path";   
    this.serverSideFormValidation              = true;
    this.sessionManagement                    = true;
    this.sessionTimeout                           = createTimeSpan(0, 0, 30, 0);
    this.setClientCookies                          = true;
    this.setDomainCookies                       = false;
    this.scriptProtect                                = false;
    this.secureJSON                                 = false;
    this.secureJSONPrefix                         = "";
    this.welcomeFileList                            = "";
    this.smtpServerSettings                      = {server="", username="", password=""};
    this.timeout                                      = 30;
    this.debugipaddress                           = "";
    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
    **********************************************/
    
    public boolean function OnApplicationStart(){
        //Handle OnApplicationStart Callback
        return true;
    }
    public void function OnApplicationEnd(struct ApplicationScope=structNew()){
        //Handle OnApplicationEnd Callback
    }
    public void function OnRequest(required string TargetPage){
        //Handle OnRequest Callback
    }
    public boolean function OnRequestStart(required string TargetPage){
        //Handle OnRequestStart Callback
        include arguments.TargetPage;                           
        return true;
    }
    public void function OnRequestEnd(){
        //Handle OnRequestEnd Callback
    }
    public void function OnCFCRequest(string cfc, string method, struct args){
        //Handle OnCFCRequest Callback
    }
    public void function OnSessionStart(){
        //Handle OnSessionStart Callback
    }
    public void function OnSessionEnd(required struct SessionScope, struct ApplicationScope=structNew()){
        //Handle OnSessionEnd Callback
    }
    public void function OnError(required any Exception, required string EventName){
        /*Handle OnError Callback
            Not all errors are caused by CodeFusion. You many wish to enable detail errors as well.
            https://solutions.hostmysite.com/index.php?/Knowledgebase/Article/View/8598/0/enable-detailed-errors

            Uncomment the line below to display errors */

        //writedump(Arguments.Exception);
    }
    public boolean function OnMissingTemplate(required string TargetPage){
        //Handle OnMissingTemplate Callback
        return true;
    }
    
}

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

Comments (0)
Copyright © 2016 HostMySite