tags:

views:

201

answers:

4

I have:

1. inetpub/wwwroot/ProjectName/Application.cfc
2. inetpub/wwwroot/ProjectName/Admin/Application.cfc

I want #2 to extend #1 and override the onRequest function. I've looked into Sean Corfields's ApplicationProxy.cfc solution, but that is if your project is in the root folder, which mine isn't.

+1  A: 

Can you create a mapping to the directory that contains App.cfc #1? If so, you may be able to extend "yourMappingName.application".

Eric
Thanks CFgears, but the extends parameter is applied before any mapping.
cf_PhillipSenn
Think mappings created in CF admin applied before extending.
Sergii
This is on a shared server, so I can't go into the CF Admin.
cf_PhillipSenn
+1  A: 

Both extends=".Application" and extends="/Application" should work if Application.cfc you need to extend is in the root.

Sergii
Thanks Sergii, but #1 is not in the root.
cf_PhillipSenn
So why can't you set extends="ProjectName.Application"?
Sergii
On dev it's in \ProjectName, but on production it's in the root.
cf_PhillipSenn
+1  A: 

In the root, create a file named AppProxy.cfc. Its contents are thus:

<cfcomponent output="false" extends="application" displayname="Application.cfc Proxy" hint="Extends the root application object so that subdirectories may extend it.">
</cfcomponent>

Then, in your subdirectory, set up your application.cfc to extend AppProxy.cfc. This will successfully inherit your root directory application.cfc methods.

<cfcomponent output="false" extends="AppProxy">
    <cffunction name="onRequestStart" output="true">
        <cfset super.onRequestStart() />
        <!--- Some other stuff happens here. --->
    </cffunction>
</cfcomponent>

This will work, by the way, even if the AppProxy isn't in the root directory. In that case, make sure your "child" application.cfc uses dot notation to find the AppProxy.

<cfcomponent output="false" extends="Path.To.Child.Directory.AppProxy">
        <cffunction name="onRequestStart" output="true">
            <cfset super.onRequestStart() />
            <!--- Some other stuff happens here. --->
    </cffunction>
</cfcomponent>
Eric Kolb
Eric, Thanks for the tip!It's the "Path.To.Child.Directory" that I'm having a problem with because on our development server it's "Projects.ClientName", but on the production server, it's in the root.
cf_PhillipSenn
I wonder if I could have the Application.cfc that's at the top of the tree extend subfolder.ApplicationProxy, and therefore the Application.cfc that's in subfolder could extend it as well! That might work!
cf_PhillipSenn
+1  A: 

I use includes in onRequestStart and onApplicationStart. That way when I am writing another Application.cfc, I can just include the code.

cf_PhillipSenn