An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Extending Application.cfc

April 28, 2005 ·

One of the cool things you can do with Application.cfc is to extend it in subdirectories to override behavior for parts of your application. This Tech Note tells you how.
Update: there is a way to extend the root Application.cfc without using a mapping. In your root directory, alongside your root Application.cfc, create ProxyApplication.cfc that contains just these two lines:
<cfcomponent extends="Application">
Now, in your subdirectory's Application.cfc you simply extend ProxyApplication (which CFMX will find in your root directory). It doesn't need mappings so it should help people on shared hosts, as well as keeping your server configuration leaner.

Tags: coldfusion

8 responses

  • 1 PaulC // Apr 29, 2005 at 9:52 AM

    This is coming from a semi-noobish standpoint, but how about tricks for controlling whether Application.cfm is used on a page or not?
  • 2 Sean Corfield // Apr 29, 2005 at 4:06 PM

    Application.cfm will be used if no Application.cfc is found first (per the documentation). Was that what you were asking?
  • 3 nobody // Oct 20, 2006 at 8:08 AM

    Is the name ProxyApplication.cfc special? Does the name matter so long as it's the same? I'd prefer to use the name ApplicationProxy.cfc just so that it sits beside Application.cfc in my directory listing.
  • 4 Sean Corfield // Oct 20, 2006 at 8:58 AM

    @nobody, you could call it &quot;Fred.cfc&quot; if you wanted. It's just a name.
  • 5 Chris // Dec 26, 2008 at 12:05 PM

    SEan - I know this is years gone by now but I can't find a better solution. Does this realyl work? I have the following setup...


    The root level app.cfc runs just fine for the root level. The ApplicationProxy.cfc contains the following:
    &lt;code&gt;&lt;cfcomponent name=&quot;ApplicationProxy&quot; extends=&quot;Application&quot;&gt;
    The admin/Application.cfc starts off with &lt;code&gt;&lt;cfcomponent name=&quot;Application&quot; output=&quot;false&quot; extends=&quot;ApplicationProxy&quot;&gt;&lt;/code&gt;

    When I run any page in the admin folder I get the following: &quot;Could not find the ColdFusion Component or Interface ApplicationProxy.&quot;

    I was entrenched in my app.cfm for so long and didn't want to make the jump b/c most of my apps have multiple levels of access just like this and I always came up lacking in the sub directories - but I just have to do it....

    Also I am not sure if it matters but my root level app.cfc does contain the onrequest method and a way to remove it should the caller be a cfc.
    &lt;code&gt;      &lt;cfif listlast(arguments.thePage,&quot;.&quot;) is &quot;cfc&quot;&gt;
             &lt;cfset StructDelete(this, &quot;onRequest&quot;) /&gt;
             &lt;cfset StructDelete(variables,&quot;onRequest&quot;)/&gt;

    Jsut hoping you can help shed seom light on it for me.

    Thanks much!
  • 6 Sean Corfield // Dec 26, 2008 at 12:23 PM

    @Chris, the only thing I can think of is that it worked on a setup that had a mapping from / to the webroot (where ApplicationProxy.cfc lives).

    After nearly four years, I don't remember what setup I used to make that work (but I'm sure it was a default install - CF *used* to have a / mapping by default but it went away at some point).
  • 7 Chris // Dec 26, 2008 at 12:42 PM

    Thanks Sean. It is funny that the link you used above has some files that extend each other by NOT using a proxy file - and they work just fine in my default cf8 dev server setup. The sub folder app file extends the root app file by using extends=&quot;RootApplicationName.Application&quot;

    But If I do exactly the same thing - it doesn't work. I know it must be something in my code - but any idea why no one seems to promote using that method in extending their app.cfc? Everywhere I look all I see is &quot;extend it using the proxy.cfc method&quot; But it seems like it is not really reliable. Just babbling now. Thanks for the response.

  • 8 Gary Fenton // Aug 8, 2009 at 6:02 PM

    4 years after Sean's blog entry and 9 months after the last comment by Chris...

    Chris, I couldn't get Sean's proxy method to work either after hours of head banging, but it did work using your simple idea of extends=&quot;RootAppName.Application&quot; which I came across as I was about to give up. Maybe because Sean's method only works with CF6 since we're going back to 2005.

    The Adobe CF docs don't explain how &quot;extends&quot; works particularly well. Glad it's sorted now. Luckily people don't shy away from commenting years after a blog entry is published. :-)