问题
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