20
Application.cfc and ColdFusion MX 7 Raymond Camden August 30, 2006

Sa204 W Cfmx7 Application Framework Camden

Embed Size (px)

DESCRIPTION

private test

Citation preview

Page 1: Sa204 W Cfmx7 Application Framework Camden

Application.cfc and ColdFusion MX 7

Raymond Camden

August 30, 2006

Page 2: Sa204 W Cfmx7 Application Framework Camden

Overview

The Old Days

Introduction to Application.cfc

onApplicationStart/End

onSessionStart/End

onRequestStart/End

onError

onRequest

Things to Look Out For…

Page 3: Sa204 W Cfmx7 Application Framework Camden

The Old Days

Page 4: Sa204 W Cfmx7 Application Framework Camden

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

Page 5: Sa204 W Cfmx7 Application Framework Camden

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”!

Page 6: Sa204 W Cfmx7 Application Framework Camden

Application.cfc – the Future is Now!

Page 7: Sa204 W Cfmx7 Application Framework Camden

Application.cfc

How is the file found? Defining settings Application.CFC Methods (think events)

Page 8: Sa204 W Cfmx7 Application Framework Camden

Application.cfc - Settings

Name ApplicationTimeout ClientManagement/ClientStorage/

SetClientCookies LoginStorage ScriptProtect (new in CFMX7) SessionManagement/SessionTimeout setDomainCookies

Page 9: Sa204 W Cfmx7 Application Framework Camden

Application.cfc - Methods

onApplicationStart/End onSessionStart/End onRequestStart/End onError onRequest

Page 10: Sa204 W Cfmx7 Application Framework Camden

onApplicationStart/End

Runs when application starts and ends (duh). There is no output when the application ends. Skip to the example…

Page 11: Sa204 W Cfmx7 Application Framework Camden

onApplicationStart/End - Uses

Initializing Application Variables– No need for locking!

Logging– How many users were using my application?

– How long was my application alive?

Page 12: Sa204 W Cfmx7 Application Framework Camden

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…

Page 13: Sa204 W Cfmx7 Application Framework Camden

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?

Page 14: Sa204 W Cfmx7 Application Framework Camden

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…

Page 15: Sa204 W Cfmx7 Application Framework Camden

onRequestStart/End - Uses

Security Setting request variables

Page 16: Sa204 W Cfmx7 Application Framework Camden

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

Page 17: Sa204 W Cfmx7 Application Framework Camden

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)

Page 18: Sa204 W Cfmx7 Application Framework Camden

onRequest - Uses

Print Format Remove Whitespace Used Rarely

Page 19: Sa204 W Cfmx7 Application Framework Camden

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

Page 20: Sa204 W Cfmx7 Application Framework Camden

Resources

My Bloghttp://ray.camdenfamily.com

Email [email protected] (home)

[email protected] (work)

Application.cfc Reference:

http://ray.camdenfamily.com/downloads/app.pdf