如何在应用程序范围的同一CFC中调用第二个功能?
-
25-10-2019 - |
题
我正在使用ColdFusion 9.0.1。
让我首先说我可能没有问正确的问题。由于每个函数都独立起作用,并且仅在一个函数调用另一个功能时才会失败,因此我认为问题在于该函数的调用方式。
我正在创建一个包含结构的应用程序变量。该结构包含对对象orders.cfc的引用。
if (not isDefined("APPLICATION.AppInfo") or not isStruct(APPLICATION.AppInfo)) {
APPLICATION.AppInfo = structNew();
APPLICATION.AppInfo.objOrders = createObject("component", "globaladmin.orders");
}
我能够成功访问orders.cfc中的方法:
OrderItemList = APPLICATION.AppInfo.objOrders.orderItemList(URL.Customer);
我在orders.cfc中使用订单中的其他方法。
<cffunction name="orderItemList">
<cfscript>
LOCAL.RandomNumber = getRandomNumber();
return LOCAL.RandomNumber;
</cfscript>
</cffunction>
<cffunction name="getRandomNumber">
<cfscript>
LOCAL.SomeNumber= randRange(0,10);
return LOCAL.SomeNumber;
</cfscript>
</cffunction>
我得到这个错误:
Entity has incorrect type for being called as a function. The symbol you provided getRandomNumber is not the name of a function.
我认为也许我不能先创建对象,因此我无法在同一CFC中引用一个函数,因此我这样做:
<cffunction name="orderItemList">
<cfscript>
LOCAL.RandomNumber = APPLICATION.AppInfo.objOrders.getRandomNumber();
return LOCAL.RandomNumber;
</cfscript>
</cffunction>
然后,我会得到这个错误:
Either there are no methods with the specified method name and argument types, or the method getRandomNumber is overloaded with arguments types that ColdFusion can't decipher reliably. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.
我应该如何在同一CFC中调用第二个功能?
解决方案
我要尝试的第一件事是在功能中范围范围范围范围:
<cffunction name="orderItemList">
<cfscript>
var RandomNumber = getRandomNumber();
return RandomNumber;
</cfscript>
</cffunction>
<cffunction name="getRandomNumber">
<cfscript>
var SomeNumber= randRange(0,10);
return SomeNumber;
</cfscript>
</cffunction>
如果这不能解决问题,请告诉我,我们可以进一步探索。
编辑好的,现在解决本地范围问题,请尝试以下操作:
<cffunction name="orderItemList">
<cfscript>
LOCAL.RandomNumber = THIS.getRandomNumber();
return LOCAL.RandomNumber;
</cfscript>
</cffunction>
<cffunction name="getRandomNumber">
<cfscript>
LOCAL.SomeNumber= randRange(0,10);
return LOCAL.SomeNumber;
</cfscript>
</cffunction>
不隶属于 StackOverflow