php - 致命错误:在布尔值上调用成员函数 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();
}
}
解决方案
当找不到块时,getBlock
返回false
而不是对象,当您尝试调用getWelcome
this 时会抛出错误。
(如果链接不起作用,则定义 getBlock):
{
if (isset($this->_blocks[$name])) {
return $this->_blocks[$name];
} else {
return false;
}
}
添加一条if
语句以在尝试对其进行操作之前检查该块是否存在。
推荐阅读
- android - Flutter 插件 - 尝试在空对象引用上调用虚拟方法
- unity3d - (统一)如何旋转子对象而不管方向?
- azure-devops - Azure Pipelines 环境批准
- react-native - 在 React Native 中重新加载上一个屏幕
- php - Codeigniter 4:开发环境工作,生产环境抛出错误
- java - 将半个数组复制到一个新数组中
- git - ERELEASEBRANCHES 发布分支在 `branches` 配置中无效。当我使用对象时
- python - Python:根据“年”、“月”、“日”列实现带有星期几的列?
- javascript - 如何在不影响其样式的情况下将事件处理程序添加到 DOM 树中的文本节点?
- botframework - Microsoft Teams 机器人发送的消息未显示在对话中