Recent
Articles |
DirectoryWatcher & ColdFusion Image Manipulation Now that ColdFusion 8 gives us a crap load of image functions as well as event gateways in all editions, I thought I'd write up a super quick demo on how you can use both in your application.
If you've never played...
Using Spry:hover, Spry:even, & Spry:odd All Together One of the nicer features of Spry is the simple way you can apply even, odd, and hover classes to a dataset. This code will tell Spry to apply a CSS class named even for even rows, odd for odd rows, and to notice...
Yahoo Strategy Includes Attracting More Developers Yahoo's old founder and new boss, Jerry Yang, outlined where the company is heading now in a blog post yesterday. The three key items he sees after talking things through with people in the company are "Become the starting point for the most consumers."...
AJAX - Too Much Choice Last week I spoke with Todd Hay, VP of Marketing at ActiveGrid. "Too often, we fight ourselves in the AJAX community. For customers, there is too much confusion between AJAX libraries such as Dojo, JQuery...
Structure Versus Query Over the weekend and Monday, there was an interesting thread on CF-Talk. You can read the complete thread here. The basic problem involved getting a particular piece of data to show up in the final feed xml, in this case, the GUID attribute for an RSS 2.0 feed.
|
|
|
11.12.07
Application.cfc Methods & Example Uses
By Raymond Camden
A reader commented yesterday that my Application.cfc reference doesn't really say how to use the various methods.
Since my reference is intended to be a simple code skeleton, I thought I'd quickly explain each of the methods and possible uses for them. Using my skeleton as a guide, let's cover the methods in order.
onApplicationStart
This method is run when the application starts up. Anything you want to define once in the life cycle of your application should be defined here. Typically this is where you will set your Application variables:
onApplicationEnd
This method is run when the application ends. You could use it for logging. Frankly, I've never used it. It's nice that it is there and all, but I haven't had a practical need for it. Since every hit will reset the application time out, and applications only timeout after two hours, only a site with minimal traffic will ever even run this.
It is important to remember that you can cannot use the Application scope here. The application is over, remember? ColdFusion passes a copy of the Application scope to the method though and you can introspect that.
onMissingTemplate
Now this is a nice one. This method is run when a request for a CFM results in a file not found. ColdFusionBloggers.org uses this. For a full blog entry on it, see: onMissingTemplate Example
onRequestStart
This method is run before your request begins. You could use it to include a header, but I think this is a bad idea. I wouldn't mix display code inside your Application.cfc. Also - there may be cases where you don't want a header (like a CFM file that returns XML or JSON). You could use it to cfinclude a UDF library. Thing is - you don't have access to the Variables scope of your page here. So if you do use this method to include a UDF library, be sure to copy your UDFs into the request scope. That's something I like to do anyway since it allows me to call the UDFs from custom tags if I need them.
onRequest
This is run when the request ends. You may be tempted to do a footer here - but again, I'd recommend against it. Honestly, I've never found a real good use for this. You could use it to log a user's "path" through your system:
Continue reading this article.
About the Author: Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com
Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.
|