ColdFusion Components Inheriting Functions Of Others

天大地大妈咪最大 提交于 2019-12-10 21:28:05

问题


I have two simple CFCs as shown below:

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>

During OnApplicationStart() of Application.cfc, I make the following calls:

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

When I dump the application scope, notice below that both components have their own function as well as the other one's function. Any idea why this is and how to correct it? Thanks.

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

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


回答1:


Because you tied this with onApplicationStart(), they were create when you first hit that web site. A quick way to reset the application variables is to rename the application.

When I develop cfc's that I know are going to be in the application scope, I work out all the details within the request scope, then once that is working right, I move the the application scope.

Another thing that is useful for debugging these kinds of issues, is to have

application.initialized = now();

That way when you do a dump of the application scope, you know when it was setup.



来源:https://stackoverflow.com/questions/20040217/coldfusion-components-inheriting-functions-of-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!