Application.cfc and ColdFusion MX 7 Raymond Camden August 30, 2006
Contact Information Raymond Camden VP of Technology, roundpeg, Inc. [email_address] [email_address] Blog: http://ray.camdenfamily.com
Overview The Old Days Introduction to Application.cfc onApplicationStart/End onSessionStart/End onRequestStart/End onError onRequest Things to Look Out For…
The Old Days
Application.cfm Loaded before any ColdFusion page CF looks in current, and parent folders It’s really just an “automatic include”! Uses <cfapplication> to define application
OnRequestEnd.cfm Loaded at the end of a CFM page CF looks in the current, and higher, folder But if it finds an Application.cfm file, it will stop looking It’s really just an “automatic include”!
Application.cfc – the Future is Now!
Application.cfc How is the file found? Defining settings Application.CFC Methods (think events)
Application.cfc - Settings Name ApplicationTimeout ClientManagement/ClientStorage/SetClientCookies LoginStorage ScriptProtect (new in CFMX7) SessionManagement/SessionTimeout setDomainCookies
Application.cfc - Methods onApplicationStart/End onSessionStart/End onRequestStart/End onError onRequest
onApplicationStart/End Runs when application starts and ends (duh). There is no output when the application ends. Skip to the example…
onApplicationStart/End - Uses Initializing Application Variables No need for locking! Logging How many users were using my application? How long was my application alive?
onSessionStart/End Runs when session starts and ends (duh). There is no output when the session ends. Pointers for Session/Application scope. NOT  run when application ends/server shuts down! Skip to the example…
onSessionStart/End - Uses Initializing session variables Logging Track number of users How long did my session last? What is the average lifespan of a session?  What was the last page of the session? What was the first page of the session?
onRequestStart/End Runs when request starts and ends (duh). Just like Application.cfm and onRequestEnd.cfm. Variables set in the method do not exist in your page. (An exception will be coming along shortly…) Skip to the example…
onRequestStart/End - Uses Security Setting request variables
onError Runs when an error occurs (duh). Doesn’t reset the output Bug: onError called with cfabort Fixed with 7.0.2! (Not exactly) http://corfield.org/blog/index.cfm/do/blog.entry/entry/onError_onRequest_and_cfabort
onRequest Allows specific control over the request. You must cfinclude the file! Copies methods, variables to Variables. Breaks FR and Web Services. Workaround (From Sean Corfield)
onRequest - Uses Print Format Remove Whitespace Used Rarely
Things to Consider… Loading UDFs Extending Application.cfc Tech Note: http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=9ce734f4 Sean Corfield’s Example: http://www.corfield.org/blog/index.cfm?do=blog.entry&entry=C8AF0DA4-0E78-FC9E-6975A16624A1E3C1 Converting from Application.cfm to Application.cfc onRequest and WS/FR
Resources My Blog http://ray.camdenfamily.com Email Me ray@camdenfamily.com (home) jedimaster@roundpeg.com (work) Application.cfc Reference: http://ray.camdenfamily.com/downloads/app.pdf

Sa204 W Cfmx7 Application Framework Camden

  • 1.
    Application.cfc and ColdFusionMX 7 Raymond Camden August 30, 2006
  • 2.
    Contact Information RaymondCamden VP of Technology, roundpeg, Inc. [email_address] [email_address] Blog: http://ray.camdenfamily.com
  • 3.
    Overview The OldDays Introduction to Application.cfc onApplicationStart/End onSessionStart/End onRequestStart/End onError onRequest Things to Look Out For…
  • 4.
  • 5.
    Application.cfm Loaded beforeany ColdFusion page CF looks in current, and parent folders It’s really just an “automatic include”! Uses <cfapplication> to define application
  • 6.
    OnRequestEnd.cfm Loaded atthe end of a CFM page CF looks in the current, and higher, folder But if it finds an Application.cfm file, it will stop looking It’s really just an “automatic include”!
  • 7.
  • 8.
    Application.cfc How isthe file found? Defining settings Application.CFC Methods (think events)
  • 9.
    Application.cfc - SettingsName ApplicationTimeout ClientManagement/ClientStorage/SetClientCookies LoginStorage ScriptProtect (new in CFMX7) SessionManagement/SessionTimeout setDomainCookies
  • 10.
    Application.cfc - MethodsonApplicationStart/End onSessionStart/End onRequestStart/End onError onRequest
  • 11.
    onApplicationStart/End Runs whenapplication starts and ends (duh). There is no output when the application ends. Skip to the example…
  • 12.
    onApplicationStart/End - UsesInitializing Application Variables No need for locking! Logging How many users were using my application? How long was my application alive?
  • 13.
    onSessionStart/End Runs whensession starts and ends (duh). There is no output when the session ends. Pointers for Session/Application scope. NOT run when application ends/server shuts down! Skip to the example…
  • 14.
    onSessionStart/End - UsesInitializing session variables Logging Track number of users How long did my session last? What is the average lifespan of a session? What was the last page of the session? What was the first page of the session?
  • 15.
    onRequestStart/End Runs whenrequest starts and ends (duh). Just like Application.cfm and onRequestEnd.cfm. Variables set in the method do not exist in your page. (An exception will be coming along shortly…) Skip to the example…
  • 16.
    onRequestStart/End - UsesSecurity Setting request variables
  • 17.
    onError Runs whenan error occurs (duh). Doesn’t reset the output Bug: onError called with cfabort Fixed with 7.0.2! (Not exactly) http://corfield.org/blog/index.cfm/do/blog.entry/entry/onError_onRequest_and_cfabort
  • 18.
    onRequest Allows specificcontrol over the request. You must cfinclude the file! Copies methods, variables to Variables. Breaks FR and Web Services. Workaround (From Sean Corfield)
  • 19.
    onRequest - UsesPrint Format Remove Whitespace Used Rarely
  • 20.
    Things to Consider…Loading UDFs Extending Application.cfc Tech Note: http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=9ce734f4 Sean Corfield’s Example: http://www.corfield.org/blog/index.cfm?do=blog.entry&entry=C8AF0DA4-0E78-FC9E-6975A16624A1E3C1 Converting from Application.cfm to Application.cfc onRequest and WS/FR
  • 21.
    Resources My Bloghttp://ray.camdenfamily.com Email Me ray@camdenfamily.com (home) jedimaster@roundpeg.com (work) Application.cfc Reference: http://ray.camdenfamily.com/downloads/app.pdf