Pedro Claudio Silva (CF-Brasil) entered this post on the "Porque CF?" blog (Why CF?). I’m translating it here:
I was reading about Application.cfc on a Ben Nadel’s post where he affirms that ” You Cannot Delete Application.cfc Methods In The Pseudo Constructor”, I agree, but I have my own solution for that and I hope it works for you.
Here is the index.cfm:<b>Pedro Claudio - pcsilva</b>
Now, my suggestion for Application.cfc:<cfcomponent output="true">
<cffunction name="OnRequestStart" output="yes" >
<cfif Isdefined("url.removeScope")>
<cfset temp = application.getApplicationSettings() >
<cfset StructDelete(temp,"OnRequestStart") >
<cfset StructDelete(temp,"OnRequest") >
<cfset StructDelete(temp,"OnRequestEnd") >
<cfreturn true>
</cfif>
<p> I am the event listener OnRequestStart(). </p>
<cfreturn true />
</cffunction>
<cffunction name="OnRequest" output="true">
<p>I am the event listener OnRequest().</p>
<cfinclude template="#arguments[1]#">
</cffunction>
<cffunction name="OnRequestEnd" output="true">
<p>I am the event listener OnRequestEnd(). </p>
</cffunction>
</cfcomponent>
Save both files in the same folder. Supposed you saved them in c:\inetpub\wwwroot\EscopoApplication\3\, let’s call the index.cfm again.
http://localhost/EscopoApplication/3/index.cfm
You see:<p>I am the event listener OnRequestStart(). </p>
<p>I am the event listener OnRequest().</p>
<b>Pedro Claudio - pcsilva</b>
<p>I am the event listener OnRequestEnd(). </p>
Now let’s call it removing the methods:
http://localhost/EscopoApplication/3/index.cfm?removeScope=true
You see:<b>Pedro Claudio - pcsilva</b>
I utilized the URL scope (url.removeScope) to be practical for this test, but you may use any scope you wish, even the session scope, just allow it in the application definition.
That’s very interesting. I don’t think I have ever seen anyone do this using the application properties struct. That’s pretty cool that that works.
Thanks for commenting, Ben. Those Brazilians are crazy. I’m translating all interesting posts I find there.
O_o, Do you find?
Pedro Claudio, yes, I think all Brazilians are crazy for coding, and they are very good professionals.
;P