Viewing By Entry / Main
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">
</cfcomponent>
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.

Comments

This is coming from a semi-noobish standpoint, but how about tricks for controlling whether Application.cfm is used on a page or not?


Application.cfm will be used if no Application.cfc is found first (per the documentation). Was that what you were asking?


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.


@nobody, you could call it "Fred.cfc" if you wanted. It's just a name.


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

c:/inetpub/wwwroot/domainname/Application.cfc c:/inetpub/wwwroot/domainname/ApplicationProxy.cfc c:/inetpub/wwwroot/domainname/admin/Application.cfc

The root level app.cfc runs just fine for the root level. The ApplicationProxy.cfc contains the following: <code><cfcomponent name="ApplicationProxy" extends="Application"> </cfcomponent></code The admin/Application.cfc starts off with <code><cfcomponent name="Application" output="false" extends="ApplicationProxy"></code>

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

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. <code> <cfif listlast(arguments.thePage,".") is "cfc"> <cfset StructDelete(this, "onRequest") /> <cfset StructDelete(variables,"onRequest")/> </cfif></code>

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

Thanks much! Chris


@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).


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="RootApplicationName.Application"

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 "extend it using the proxy.cfc method" But it seems like it is not really reliable. Just babbling now. Thanks for the response.

Chris


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="RootAppName.Application" 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 "extends" works particularly well. Glad it's sorted now. Luckily people don't shy away from commenting years after a blog entry is published. :-)


Post Your Comments
Name:
Email Address:
Comments
*** Please note that all comments require moderation so it may be some time before your comment posts to this blog! ***
Remember My Information:
 



Hosting provided by