我在Prestashop模块中开发了一个自定义页面。
我使用Prestashop 1.7.7.2和PHP7.4。
这是控制器代码:
class MymoduleConfirmemailModuleFrontController extends ModuleFrontController
{
public $php_self = 'confirmemail';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate('confirmemail');
}这是模板文件的代码:
{extends file='page.tpl'}
{block name='page_header_container'}{/block}
{block name='page_content'}
<div>TEST</div>
{/block}当我导航到相应的页面时,我会收到以下错误:
注意:尝试访问bool类型值的数组偏移量。
页面不显示。如果我删除行{extends file='page.tpl'},它将按预期显示"TEST“。
在堆栈跟踪之后,经过一些调试之后,我发现问题在classes/Connection.php中的这些行中:
[...]
$sql = 'SELECT SQL_NO_CACHE `id_guest`
FROM `' . _DB_PREFIX_ . 'connections`
WHERE `id_guest` = ' . (int) $cookie->id_guest . '
AND `date_add` > \'' . pSQL(date('Y-m-d H:i:00', time() - 1800)) . '\'
' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
ORDER BY `date_add` DESC';
$result = Db::getInstance()->getRow($sql, false);
---> if (!$result['id_guest'] && (int) $cookie->id_guest) {
[...]问题是查询返回false,因为没有包含id id_guest的行,所以最后一行会抛出一个错误。我遗漏了什么?
发布于 2021-10-18 23:39:58
我通过测试getCoverWs是否返回任何结果集,如果没有返回false来解决这个问题。我的代码将更改为类/Product.php上的以下内容
public function getCoverWs()
{
$result = $this->getCover($this->id);
if (!$result) {
return false;
}
return $result['id_image'];
}https://stackoverflow.com/questions/66867369
复制相似问题