本文介绍了致命错误:在布尔值上调用成员函数getWelcome()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道

如何解决Magento 1.7中的此错误?

How to solve this error in Magento 1.7?

class Mage_Page_Block_Html_Welcome extends Mage_Core_Block_Template
{
    /**
     * Get block messsage
     *
     * @return string
     */
    protected function _toHtml()
    {
                return Mage::app()->getLayout()->getBlock('header')->getWelcome();

    }
}

推荐答案

检查 http://freegento.com/doc/d7/d92/class_mage___core___model___layout.html#4c2f3ed0733b1d16c6b9d1d13898574f

当找不到该块时,getBlock返回false而不是对象,并且当您尝试对此调用getWelcome时抛出错误.

When the block can't be found, the getBlock returns false instead of an object, and the error is thrown when you try to call getWelcome on this.

(在链接无效的情况下定义getBlock):

(definition of getBlock in case the link doesn't work):

{
         if (isset($this->_blocks[$name])) {
             return $this->_blocks[$name];
         } else {
             return false;
         }
     }

添加if语句以在尝试对其进行操作之前检查该块是否存在.

Add an if statement to check if the block exists before trying to operate on it.

这篇关于致命错误:在布尔值上调用成员函数getWelcome()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:00