首页 > 解决方案 > 致命错误:在布尔值上调用成员函数 getWelcome()

问题描述

我明白了

php 致命错误:在第 43 行的 /home/cloudpanel/htdocs/domain.com/app/code/core/Mage/Page/Block/Html/Welcome.php 中的布尔值上调用成员函数 getWelcome()。

如何解决 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();

    }
}

标签: phpmagento-1.7

解决方案


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

当找不到块时,getBlock返回false而不是对象,当您尝试调用getWelcomethis 时会抛出错误。

(如果链接不起作用,则定义 getBlock):

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

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


推荐阅读