Coldfusion Application.cfc将值扩展到子文件夹

Coldfusion Application.cfc将值扩展到子文件夹,coldfusion,application.cfc,Coldfusion,Application.cfc,我目前正在更新我的一些Coldfusion应用程序,我正在寻找一种好的方法来保持某些结构 目前,它的设置是这样的 目前,安装程序在每个目录中使用一个应用程序文件,它确实可以工作,但由于重新声明了应用程序/会话范围之类的所有内容,它变得很混乱。有更好的方法吗?我想在您的应用程序中尝试类似的方法。请求启动时的cfc: <cffunction name="onRequestStart" returnType="boolean" output="false" hint="I handle page

我目前正在更新我的一些Coldfusion应用程序,我正在寻找一种好的方法来保持某些结构

目前,它的设置是这样的


目前,安装程序在每个目录中使用一个应用程序文件,它确实可以工作,但由于重新声明了应用程序/会话范围之类的所有内容,它变得很混乱。有更好的方法吗?

我想在您的应用程序中尝试类似的方法。请求启动时的cfc:

<cffunction name="onRequestStart" returnType="boolean" output="false" hint="I handle page requests." >
  <cfargument name="requestname" type="string" required="true" >

  <cfif FileExists(GetDirectoryFromPath(arguments.requestname) & '/admin.cfm')>
    <cfinclude template="#GetDirectoryFromPath(arguments.requestname)#/admin.cfm">
  </cfif>
</cffunction>

然后,在每个要设置自定义变量的目录中,放置一个admin.cfm文件。在这个admin.cfm文件中,只需放置一堆标记,或者设置会话和应用程序变量

我会在您的应用程序中尝试类似的操作。请求启动时的cfc:

<cffunction name="onRequestStart" returnType="boolean" output="false" hint="I handle page requests." >
  <cfargument name="requestname" type="string" required="true" >

  <cfif FileExists(GetDirectoryFromPath(arguments.requestname) & '/admin.cfm')>
    <cfinclude template="#GetDirectoryFromPath(arguments.requestname)#/admin.cfm">
  </cfif>
</cffunction>
然后,在每个要设置自定义变量的目录中,放置一个admin.cfm文件。在这个admin.cfm文件中,只需放置一堆标记,或者设置会话和应用程序变量

在admin子目录的Application.cfc中,扩展父目录中的一个,例如:

component extends="ApplicationProxy" {

    // eg: if you need to do something different in the local onApplicationStart:
    public void function onApplicactionStart(){
        super.onApplicationStart();
        // stuff that's different from the parent goes here
    }    

    // if there's nothing different for a given handler, then don't have one in here: the super one will still fire

    // otherwise override each handler in a similar fashion to the onApplicationStart above, with:
    // a) a call to its super equivalent
    // b) anything that needs overriding

}
在基本目录中,添加ApplicationProxy.cfc,因此:

原因是sub Application.cfc不能有extends=Application,因为这看起来像是循环引用。但是,没有更好的限定方法来标识基本目录中的Application.cfc,因此需要一个代理。

在管理子目录中的Application.cfc中,扩展父目录中的一个,例如:

component extends="ApplicationProxy" {

    // eg: if you need to do something different in the local onApplicationStart:
    public void function onApplicactionStart(){
        super.onApplicationStart();
        // stuff that's different from the parent goes here
    }    

    // if there's nothing different for a given handler, then don't have one in here: the super one will still fire

    // otherwise override each handler in a similar fashion to the onApplicationStart above, with:
    // a) a call to its super equivalent
    // b) anything that needs overriding

}
在基本目录中,添加ApplicationProxy.cfc,因此:


原因是sub Application.cfc不能有extends=Application,因为这看起来像是循环引用。但是,没有更好的方法在base dir中标识Application.cfc,因此需要一个代理。

您也可以检查用户正在执行的目录,然后运行额外的代码。例如,在主应用程序.cfc onRequestStart中,您可以说,当前请求是否为admin文件夹?好的,运行包含所有安全功能的函数X。如果愿意,您甚至可以将此代码作为附加函数包含在application.cfc中

或者,如果您通过执行extends之类的操作来使用其他答案之一,那么您将希望在希望运行其他代码的每个函数中放置一个super.function调用。例如,对于onRequest start,super.onRequestStart位于子应用程序的开头。cfc onRequestStart在子应用程序启动之前调用父对象


我个人更喜欢第一种方法,因为当您确实只有一个应用程序时,它可以保持它的整洁。

您也可以检查用户正在执行的目录,然后运行额外的代码。例如,在主应用程序.cfc onRequestStart中,您可以说,当前请求是否为admin文件夹?好的,运行包含所有安全功能的函数X。如果愿意,您甚至可以将此代码作为附加函数包含在application.cfc中

或者,如果您通过执行extends之类的操作来使用其他答案之一,那么您将希望在希望运行其他代码的每个函数中放置一个super.function调用。例如,对于onRequest start,super.onRequestStart位于子应用程序的开头。cfc onRequestStart在子应用程序启动之前调用父对象


我个人更喜欢第一种方法,因为当你真的只有一个应用程序时,它可以保持它的整洁。

Hah,我不记得21分钟前在这里看到过这个答案PHah,我不记得21分钟前在这里看到过这个答案p虽然你可以这样做,但它的工作方式与应用程序框架(即application.cfc)的预期相反。为超级材料的澄清干杯。我忘了在我的回答中提到这一点,现在增加了一个例子。虽然你可以这样做,但这与应用程序框架(即application.cfc)的预期方式背道而驰。为超级材料的澄清干杯。在我的回答中,我忘了提到这一点,现在我增加了一个例子。Sean Corfield有一篇关于扩展root Application.cfc的博客文章。可能还想搜索归档文件,因为有几个关于Sean Corfield的现有线程,他有一篇关于扩展root Application.cfc的博客文章。可能还想搜索归档文件,因为有几个关于我基本上做了这个使用过的映射而不是ApplicationProxy的线程,但是想法是sameI基本上做了这个使用过的映射而不是ApplicationProxy,但是想法是一样的