Fatal error: Call to a member function getWelcome() on boolean

Fatal error: Call to a member function getWelcome() on boolean

我明白了

php fatal error: Call to a member function getWelcome() on boolean in /home/cloudpanel/htdocs/domain.com/app/code/core/Mage/Page/Block/Html/Welcome.php on line 43.

如何解决 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 returns false 而不是对象,当您尝试调用 getWelcome 时抛出错误关于这个。

(getBlock 的定义,以防 link 不起作用):

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

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