如何修复 Prestashop php 文件中的此通知?

How to fix this notice in Prestashop php file?

我是 运行 Prestashop 网站,我网站的几乎每个页面(在网站顶部)都显示一小段文字说:

Notice: Undefined index: link_rewrite in /srv/http_mysitename/shop/modules/blockcms/BlockCMSModel.php on line 280
Notice: Undefined index: meta_title in /srv/http_mysitename/shop/modules/blockcms/BlockCMSModel.php on line 281

这是我的BlockCMSModel.php:http://codepen.io/Janos/pen/xExGww?editors=1000 → 第 280 和 281 行是:

        $content[$cmsCategory]['link'] = $context->link->getCMSLink((int)$ids[1], $query['link_rewrite']);
        $content[$cmsCategory]['meta_title'] = $query['meta_title'];

请帮助我,我不是程序员,我只能处理一些 html 和 css 的事情。我办公室的同事给了我一个关于如何隐藏这些通知的建议,但我宁愿解决整个问题。 谢谢。

可能 $query = BlockCMSModel::getCMSMetaTitle($ids[1]); 中的查询返回 0 行,因此 $query 是空的 array(),没有键 link_rewritemeta_title

通过添加条件来解决此问题,以处理查询 returns 无行

时发生的情况
$query = BlockCMSModel::getCMSMetaTitle($ids[1]); //line 279
if (!$query) {
    // set empty strings when no rows are found in database or change this to
    // whatever you want to do when no rows are found
    $query['link_rewrite'] = '';
    $query['meta_title'] = '';
}
$content[$cmsCategory]['link'] = $context->link->getCMSLink((int)$ids[1], $query['link_rewrite']);
$content[$cmsCategory]['meta_title'] = $query['meta_title'];

或打开文件

config/defines.inc.php

并设置define('_PS_MODE_DEV_', false);

请注意,此设置只会隐藏您网站上的错误输出。