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>
   <p> I am the event listener OnRequestStart(). </p>
   <cfreturn true />
<cffunction name="OnRequest" output="true">
   <p>I am the event listener OnRequest().</p>
   <cfinclude template="#arguments[1]#">
<cffunction name="OnRequestEnd" output="true">
   <p>I am the event listener OnRequestEnd(). </p>

Save both files in the same folder. Supposed you saved them in c:\inetpub\wwwroot\EscopoApplication\3\, let’s call the index.cfm again.
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:
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.

5 thoughts on “Excluding a Method During Another Method (Application.cfc)

  1. 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.