开发者

Magento Error Call to a member function setCollection() on a non-object

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\开发者_Go百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜