问题
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