0

我有:

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

我希望 #2 扩展 #1 并覆盖 onRequest 函数。我已经查看了 Sean Corfields 的 ApplicationProxy.cfc 解决方案,但那是如果您的项目位于根文件夹中,而我的不是。

4

4 回答 4

1

您可以创建到包含 App.cfc #1 的目录的映射吗?如果是这样,您可以扩展“yourMappingName.application”。

于 2010-01-06T18:43:43.330 回答
1

如果您需要扩展的 Application.cfc 在根目录中,则extends=".Application"extends="/Application"都应该可以工作。

于 2010-01-06T21:23:28.350 回答
1

在根目录中,创建一个名为 AppProxy.cfc 的文件。它的内容是这样的:

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

然后,在您的子目录中,设置您的 application.cfc 以扩展 AppProxy.cfc。这将成功地继承你的根目录 application.cfc 方法。

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

顺便说一句,即使 AppProxy 不在根目录中,这也将起作用。在这种情况下,请确保您的“子”application.cfc 使用点表示法来查找 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>
于 2010-01-19T19:39:17.737 回答
1

我在 onRequestStart 和 onApplicationStart 中使用包含。这样,当我编写另一个 Application.cfc 时,我可以只包含代码。

于 2010-08-07T00:06:30.903 回答