oop - 如何使用 cfinclude 拆分组件并仍然使用继承?

标签 oop coldfusion cfwheels

更新:似乎railo完全没有这个问题。

更新:我投票决定关闭这个问题,因为我觉得人们更关注这个问题的整体“有人有更好的想法拆分大型组件”部分(我不应该放入)那么使用 cfincludes 和 cfcomponent 的真正问题。

注意:这只是一个简化的例子,说明我正在尝试做的事情来让人们理解这个想法。

我遇到的问题是我想在 cfcomponent 中使用 cfinclude,这样我就可以将类似的方法分组到单独的文件中,以提高可管理性。我遇到的问题是当我尝试扩展另一个组件时,该组件也使用 cfinclude 来管理它的方法,如下所示。请注意,ComponentA 扩展了 ComponentB:

ComponentA
==========
<cfcomponent output="false" extends="componentb">
    <cfinclude template="componenta/methods.cfm">
</cfcomponent>

componenta/methods.cfm
======================
<cffunction name="a"><cfreturn "componenta-a"></cffunction>
<cffunction name="b"><cfreturn "componenta-b"></cffunction>
<cffunction name="c"><cfreturn "componenta-c"></cffunction>
<cffunction name="d"><cfreturn super.a()></cffunction>

ComponentB
==========
<cfcomponent output="false">
    <cfinclude template="componentb/methods.cfm">
</cfcomponent>

componentb/methods.cfm
======================
<cffunction name="a"><cfreturn "componentb-a"></cffunction>
<cffunction name="b"><cfreturn "componentb-b"></cffunction>
<cffunction name="c"><cfreturn "componentb-c"></cffunction>

问题是,当我尝试初始化 ComponentA 时出现错误:“例程不能多次声明。例程 a 已在不同模板中声明两次。”

这样做的全部原因是因为当您使用 cfinclude 时,它​​是在运行时而不是编译时求值的。

如果没有将方法移到组件本身并消除 cfinclude 的使用,我该如何解决这个问题,或者有人有更好的主意来拆分大型组件吗?

最佳答案

未测试,但我会尝试将每个函数的内容放入包含中,但在组件文件本身中定义函数。 `

<cfcomponent name="a">
    <cffunction name="aa">
        <cfinclude template="componenta/functiona.cfm" />
    </cffunction>
</cfcomponent>

祝你好运。

关于oop - 如何使用 cfinclude 拆分组件并仍然使用继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3030056/

相关文章:

web-services - 使用 ColdFusion 访问安全的 Web 服务

coldfusion - 使用 cfwheels、coldfusion 和 cfspreadsheet 创建具有非标准列名称(带空格)的 excel 文件导出

coldfusion - 从 ColdFusion Fusebox 5.5 noxml 转换

c++ - 在 C++ 中重载显式构造函数

java - java.lang.Runtime 是报告整个 Coldfusion 服务器的内存使用情况还是只报告一页?

java - 根据总值对对象数组列表进行排序

coldfusion - 使用数据格式时逗号无效

apache - 使用用于 cf wheels 的 railo tomcat apache 重写 url

design-patterns - 垂头丧气可以吗?

PHP类问题