I'm working in a legacy app that was built upon the use of Application.cfm
files rather than Application.cfc
files.
There is a need to be able to run code after a request has processed. (Basically, I am wanting to use the <cfhtmlhead>
tag to inject some Javascript and CSS files into every loaded document. Before I was doing this with a GreaseMonkey user script, but something server-side would be best.)
From what I read, I think I should be able to do this with the onRequestEnd()
function, however, I've only ever seen that referenced in regards to Application.cfc
files. I have read that you can put an onRequestEnd.cfm
file in the same directory as an Application.cfm
file to have it register it to the onRequestEnd()
function, but the system does not map to one Application.cfm
file (i.e. I would have to throw this onRequestEnd.cfm
file in a lot of directories).
Is there some other way to register this onRequestEnd()
function using an Application.cfm
setup? In case it matters, we are running Coldfusion 9.
Just to clarify, the
onRequestEnd()
method is only available if you are utilizing theApplication.cfc
file.The
OnRequestEnd.cfm
file does indeed work like theApplication.cfm
file in that ColdFusion automatically looks for it and will process it's contents when found. Do note that you cannot use an OnRequestEnd.cfm page if you have an Application.cfc file for your application. So assuming that you have noApplication.cfc
files for your application and are only usingApplication.cfm
files then theOnRequestEnd.cfm
file should work for you. All you need to do is insert the CFML code that you would like to be executed after the page request into that file.If you have several
Application.cfm
files spread out in various folders then, yes, you will also need to copy/create theOnRequestEnd.cfm
files in those directories as well. You might be able to copy stubOnRequestEnd.cfm
files in those directories that do nothing more thancfinclude
your actual code from another, single, location. At least that way once you have all of the stub files out there you can modify the code in a single place.See the documentation for Structuring an application (it was written for ColdFusion 8 but the same rules still apply). In case that page is taken down, here is the relevant text:
Since you are using ColdFusion 9, it would be fairly trivial to upgrade to using Application.cfc instead of trying to figure out how to plug in OnRequestEnd.cfm files. Plus, there are advantages to using Application.cfc to Application.cfm.
A few references:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=appFramework_15.html
http://forum.hostek.com/showthread.php?724-Converting-to-Application-cfc
http://www.bennadel.com/blog/726-ColdFusion-Application-cfc-Tutorial-And-Application-cfc-Reference.htm
http://www.raymondcamden.com/index.cfm/2009/12/30/Best-of-CF9-Applicationcfc-Script-Template
http://cfruss.blogspot.com/2009/11/applicationcfc-reference-in-cfscript.html