ColdFusion组件继承其他人的功能

时间:2013-11-18 04:40:54

标签: inheritance coldfusion components extends cfc

我有两个简单的CFC,如下所示:

Test1.cfc

<cfcomponent> 
  <cffunction name="initMethod1" access="private" returntype="boolean"> 
  <cfreturn true />
</cfcomponent>

Test2.cfc

<cfcomponent> 
  <cffunction name="initMethod2" access="private" returntype="boolean"> 
  <cfreturn true />
</cfcomponent>

在Application.cfc的OnApplicationStart()期间,我进行以下调用:

<cfset application["Test1"] = CreateObject("component","jbx.c.Test1") />
<cfset application["Test2"] = CreateObject("component","jbx.c.Test2") />

当我转储应用程序范围时,请注意下面两个组件都有自己的功能以及另一个组件的功能。知道这是为什么以及如何纠正它?谢谢。

Test 1 Object http://www.signaturehairbyrisa.com/test1.png

Test 2 Object http://www.signaturehairbyrisa.com/test2.png

1 个答案:

答案 0 :(得分:0)

因为你将它与onApplicationStart()绑定在一起,所以当你第一次访问该网站时就会创建它们。重置应用程序变量的一种快速方法是重命名应用程序。

当我开发我知道将在应用程序范围内的cfc时,我会在请求范围内计算出所有细节,然后一旦工作正常,我就会移动应用程序范围。

另一件对调试这类问题有用的事情就是

application.initialized = now();

这样,当您执行应用程序范围的转储时,您就知道它何时被设置。