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

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

问题描述

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


  1. wwwroot\site\application.cfc

  2. wwwroot\site\dir\application.cfc

去声明组件的第二个文件,我不知道什么放在extends属性。 我的问题是,几个开发网站(与共享的SVN存储库)正在运行ColdFusion的同一个实例,所以我不能只是创建一个映射在CF管理员,如:

 < cfcomponent extends =site.application>但是,ColdFusion不喜欢:


< cfcomponent extends =.. application>

或任何动态输入:

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

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



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



编辑以澄清:ApplicationProxy解决方案不工作,因为上面的粗体文本。现在,作为解决方法,我们不是将\dir\application.cfc检查为SVN,以便每个开发人员可以保留一个扩展他/她自己的root应用程序的版本。显然这不太理想。

解决方案

以下代码适用于我。我注意到的一个事情是,application.cfc似乎被缓存,所以对父应用程序cfc的更改可能不会被反映。我通过对子应用程序cfc进行微小的更改来解决这个问题。

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

< cfloop item =variables.keycollection =#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>
< cffunction name =onApplicationStartoutput =false>
< cfset super.onApplicationStart()/>
< / cffunction>


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

  1. wwwroot\site\application.cfc
  2. wwwroot\site\dir\application.cfc

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">

However, ColdFusion doesn't like:

<cfcomponent extends="..application">

or any dynamic input like:

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

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?

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 \dir\application.cfc into SVN so that each developer can keep a version that extends his/her own root application.cfc. Obviously, this is not ideal.

解决方案

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天全站免登陆