如何在 APPLICATION 范围内的同一 CFC 中调用第二个函数?
我正在使用 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");
}
我能够成功访问 order.cfc 中的方法,如下所示:
OrderItemList = APPLICATION.AppInfo.objOrders.orderItemList(URL.Customer);
我在orders.cfc 中有调用 order.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.
I我想,如果不首先创建对象,我可能无法引用同一个 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 中调用第二个函数?
I am using ColdFusion 9.0.1.
Let me start by stating that I may not be asking the right question. Since each function works independently and fails only when one function calls another, I am thinking that the problem is in how the function is called.
I am creating an application variable that contains a structure. The structure contains the reference to an object, orders.cfc.
if (not isDefined("APPLICATION.AppInfo") or not isStruct(APPLICATION.AppInfo)) {
APPLICATION.AppInfo = structNew();
APPLICATION.AppInfo.objOrders = createObject("component", "globaladmin.orders");
}
I am able to successfully access the methods in the orders.cfc like this:
OrderItemList = APPLICATION.AppInfo.objOrders.orderItemList(URL.Customer);
I have methods in the orders.cfc that call other methods in the order.cfc, kind of like this (faked for simplicity):
<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>
I get this error:
Entity has incorrect type for being called as a function. The symbol you provided getRandomNumber is not the name of a function.
I figured maybe I can't reference a function within the same CFC without creating an object first, so I do this:
<cffunction name="orderItemList">
<cfscript>
LOCAL.RandomNumber = APPLICATION.AppInfo.objOrders.getRandomNumber();
return LOCAL.RandomNumber;
</cfscript>
</cffunction>
Then, I'd get this error:
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.
How should I call a second function within the same CFC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要尝试的第一件事是 var 确定函数中所有变量的作用域:
如果这不能解决问题,请告诉我,我们可以进一步探索。
编辑
好的,既然本地范围问题已经解决,请尝试以下操作:
The first thing I would try is var scoping your all your variables within your functions:
If that doesn't solve the problem, let me know and we can explore further.
edit
Okay, now that the local scope issue is resolved, try this: