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

梦想与她 提交于 2019-12-23 04:49:12

问题


I get

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.

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();

    }
}

回答1:


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

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.

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

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

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



来源:https://stackoverflow.com/questions/59399906/fatal-error-call-to-a-member-function-getwelcome-on-boolean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!