开发者

extend Application.cfc, but not from the root

I have:

1. in开发者_如何学Goetpub/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.


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


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


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜