本文介绍了致命错误:在布尔值上调用成员函数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();
}
}
推荐答案
当找不到该块时,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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!