Magento 错误调用非对象上的成员函数 setCollection()

发布于 2024-10-07 01:35:54 字数 335 浏览 0 评论 0原文

我的 Magento 有问题。当我登录并查看我的订单页面时,显示以下错误:

致命错误:在第 58 行对 C:\wamp\www\danfemall\app\code\core\Mage\Sales\Block\Order\History.php 中的非对象调用成员函数 setCollection()< /p>

当我删除从代码中删除 setCollection 函数,它运行良好,但我想知道 setCollection 函数的作用是什么,以及从代码中删除该函数是否明智。

请有人帮助我。

I have a problem with my Magento. When I login and view my orders page, the following error is shown:

Fatal error: Call to a member function setCollection() on a non-object in C:\wamp\www\danfemall\app\code\core\Mage\Sales\Block\Order\History.php on line 58

When I remove the setCollection function from the code, it runs well but I wonder what the setCollection function does and is it wise to remove that function from the code.

Please someone help me out.

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

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

发布评论

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

评论(1

赠意 2024-10-14 01:35:54

Magento 版本号在调试 Mangeto 问题时总是有帮助的。另外,android(你的标签)适合在哪里?

假设以下行是给您的系统带来麻烦的行,

$pager = $this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')
    ->setCollection($this->getOrders());

Magento 正在尝试创建一个 page/html_pager 块对象(假设没有覆盖,则对应于 Mage_Page_Block_Html_Pager)。

在工作系统中,这是通过以下调用完成的。

$this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')

它返回 Block 对象,然后调用 Block 的 setCollection 方法。

->setCollection($this->getOrders());

但是,在您的系统中,createBlock 方法没有返回对象,我猜测它返回的是布尔值。看一下 Layout 类的 createBlock 方法的开头。

#File: app/code/core/Mage/Core/Model/Layout.php
public function createBlock($type, $name='', array $attributes = array())
{
    try {
        $block = $this->_getBlockInstance($type, $attributes);
    } catch (Exception $e) {
        Mage::logException($e);
        return false;
    }

因此,您的系统已被更改或配置为尝试创建 page/html_pager 块会引发异常。检查您的 Magento 异常日志以查看记录了哪些类型的错误,或者只是暂时放入 var_dump

try {
    $block = $this->_getBlockInstance($type, $attributes);
} catch (Exception $e) {
    var_dump($e->getMessage()); //don't forget to remove me before pushing 
                                //to production
    Mage::logException($e);
    return false;
}

至于此代码的作用以及它将如何影响您的系统,setCollection< /code> 方法将一个集合对象(类似于模型对象的数组)添加到您的 Block 对象中。如果没有集合,您的寻呼机块将(很可能)无法正确呈现。

Magento version numbers always help when debugging Mangeto problems. Also, where does android (your tag) fit in?

Assuming the following line is the one that's causing you trouble on your system

$pager = $this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')
    ->setCollection($this->getOrders());

Magento is trying to create a page/html_pager block object (which, assuming no overrides are in place, corresponds to a Mage_Page_Block_Html_Pager).

In a working system, that's done with the following call.

$this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')

which returns the Block object, and then the setCollection method of the Block is called

->setCollection($this->getOrders());

However, in your system, the createBlock method isn't returning an object, and my guess is it's returning a boolean. Take a look at the start of the Layout class's createBlock method.

#File: app/code/core/Mage/Core/Model/Layout.php
public function createBlock($type, $name='', array $attributes = array())
{
    try {
        $block = $this->_getBlockInstance($type, $attributes);
    } catch (Exception $e) {
        Mage::logException($e);
        return false;
    }

So, your system's been altered or is configured in such a way that attempts to create the page/html_pager block are throwing an exception. Check your Magento exception log to see what kind of errors are being logged, or just temporarily drop in a var_dump

try {
    $block = $this->_getBlockInstance($type, $attributes);
} catch (Exception $e) {
    var_dump($e->getMessage()); //don't forget to remove me before pushing 
                                //to production
    Mage::logException($e);
    return false;
}

As far as what this code does and how it will affect your system, the setCollection method adds a collection object (an array like object of models) to your Block object. Without a collection, your pager block will (most likely) not render correctly.

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