在子目录中扩展 application.cfc [英] Extending application.cfc in a subdirectory

查看:19
本文介绍了在子目录中扩展 application.cfc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两个文件,并希望第二个扩展第一个:

I have the following two files and would like the second to extend the first:

  1. wwwrootsiteapplication.cfc
  2. wwwrootsitedirapplication.cfc

但是,当我去为第二个文件声明组件时,我不确定在 extends 属性中放置什么.我的问题是几个开发站点(具有共享的 SVN 存储库)在同一个 ColdFusion 实例上运行,所以我不能像这样在 CF 管理员中创建映射:

However, when I go to declare the component for the second file, I'm not sure what to put in the extends attribute. My problem is that several dev sites (with a shared SVN repository) are running off the same instance of ColdFusion, so I can't just create a mapping in the CF admin like so:

<cfcomponent extends="site.application">

但是,ColdFusion 不喜欢:

However, ColdFusion doesn't like:

<cfcomponent extends="..application">

或任何动态输入,例如:

or any dynamic input like:

<cfcomponent extends="#expandpath('..').#application">

创建运行时映射(像这里)不会似乎也有可能.在基础 application.cfc 中创建它是没有用的,因为在声明继承 cfc 时该代码尚未执行;而且我无法在定义继承组件之前创建映射,因为还没有应用程序可以附加它.

Creating a runtime mapping (like here) doesn't seem possible either. Creating it in the base application.cfc is useless because that code hasn't yet executed by the time the inheriting cfc is being declared; and I can't create the mapping before the inheriting component is defined because there isn't yet an application to attach it to.

有什么方法可以引用父目录来完成我的扩展?

Is there any way I can reference the parent directory to accomplish my extends?

编辑澄清:由于上面的粗体文本,ApplicationProxy 解决方案不起作用.现在,作为一种解决方法,我们只是不将 dirapplication.cfc 检入 SVN,以便每个开发人员都可以保留扩展他/她自己的根 application.cfc 的版本.显然,这并不理想.

Edit to clarify: The ApplicationProxy solution doesn't work because of the bolded text above. Right now, as a workaround, we're simply not checking the dirapplication.cfc into SVN so that each developer can keep a version that extends his/her own root application.cfc. Obviously, this is not ideal.

推荐答案

以下代码对我有用.我注意到的一件事是 application.cfc 似乎被缓存了,因此对父应用程序 cfc 的更改可能不会被反映.我通过对子应用程序 cfc 进行微不足道的更改来解决这个问题.

The following code is working for me. One thing I noticed though is that the application.cfc seems to get cached, so changes to the parent application cfc might not be reflected. I got around this by doing a trivial change to the child application cfc.

<cfcomponent output="false">
        <cfset variables.higherPath = ReReplace(GetMetaData(this).name,".[^.]+.[^.]+$","") />
        <cfset variables.extendApp = CreateObject("component", "#variables.higherPath#.Application") />

        <cfloop item="variables.key" collection="#variables.extendApp#">
            <cfif IsCustomFunction(variables.extendApp[variables.key])>
                <cfset super[variables.key] = variables.extendApp[variables.key]>
            <cfelse>
                <cfset this[variables.key] = variables.extendApp[variables.key] >
            </cfif>
        </cfloop>
        <cffunction name="onApplicationStart" output="false">
            <cfset super.onApplicationStart() />
        </cffunction>

这篇关于在子目录中扩展 application.cfc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆