我应该调用扩展 CFC 还是父 CFC?

发布于 2024-12-22 07:18:05 字数 622 浏览 1 评论 0原文

我正在使用 ColdFusion 9.1.2。

我有一个名为 order.cfm 的 CFC。这是“父”CFC。

我有另一个 CFC 调用 orderswrapup.cfc。这是orders.cfc 的扩展。在 orderswrapup.cfc 中,我在顶部有这一行:

<cfcomponent extends="orders">

现在,这不起作用:

objOrders = createObject("component", "orders");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

但这确实有效:

objOrders = createObject("component", "orderswrapup");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

要访问 orderswrapup.cfc 中的方法,我可以像“在”订单中一样调用该方法吗? cfc 还是我需要直接调用它?看来我应该可以打电话给家长,而不是孩子。

I am using ColdFusion 9.1.2.

I have a CFC called orders.cfm. This is the "parent" CFC.

I have another CFC call orderswrapup.cfc. This is an extension of orders.cfc. In orderswrapup.cfc, I have this line at the top:

<cfcomponent extends="orders">

Right now, this doesn't work:

objOrders = createObject("component", "orders");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

But this does work:

objOrders = createObject("component", "orderswrapup");
MyResult = objOrders .someMethodActuallyInOrdersWrapUpCFC();

To access the methods in orderswrapup.cfc, can I call the method as though it were "in" orders.cfc or do I need to call it directly? It seems that I should be able to call the parent, not the child.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

情绪操控生活 2024-12-29 07:18:05

当您创建新的 orderswrapup 对象时,orderswrapup 可以访问 order 的所有函数,因为 orderswrapup 是 order 的子级。

当您将 orderswrapup.cfc 定义为 时,您将orderswrapup.cfc定义为继承orders.cfc的所有函数。这允许您通过orderswrapup调用orders.cfc中的任何函数.cfc 就好像它们是orders.cfc 内部的函数。但orders.cfc与orderswrapup.cfc没有定义的关系,因此它无法调用orderswrapup.cfc内部的函数

一些好的文章 - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=buildingComponents_30.html

orderswrapup has access to all of order's functions, when you create a new orderswrapup object because orderswrapup is a child of order.

You defined orderswrapup.cfc to inherit all of orders.cfc's functions when you defined orderswrapup.cfc as <cfcomponent extends="orders"> This allows you to call any functions in orders.cfc via orderswrapup.cfc as if they were functions inside of orders.cfc. But orders.cfc has no defined relationship with orderswrapup.cfc, so it can't call functions inside of orderswrapup.cfc

Some good writeups - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=buildingComponents_30.html

胡渣熟男 2024-12-29 07:18:05

扩展 cfc 的成本很高...

如果您发现自己需要扩展超过 3 个级别,您就会开始注意到性能受到影响。

Extending cfcs is expensive...

If you find yourself needing to go more than 3 levels of extending, you'll start to notice a performance hit.

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