如何在 APPLICATION 范围内的同一 CFC 中调用第二个函数?

发布于 2024-12-18 18:28:11 字数 1842 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九歌凝 2024-12-25 18:28:11

我要尝试的第一件事是 var 确定函数中所有变量的作用域:

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

The first thing I would try is var scoping your all your variables within your functions:

<cffunction name="orderItemList">
    <cfscript>
          var RandomNumber = getRandomNumber();
          return RandomNumber;
    </cfscript>
</cffunction>

<cffunction name="getRandomNumber">
    <cfscript>
        var SomeNumber= randRange(0,10);
        return SomeNumber;
    </cfscript>
</cffunction>

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:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文