我开发了一个prestashop模块,当我在我的模块的后台时,我有很多错误:
通知la la ligne 30 du fichier C:\ xampp2 \ htdocs中\ projet_presta \程序\缓存\ dev的\智者\编译\ 86 \ 1C \ 1C \ 861c1cb1906b13002a1460e54203e8a370598366.file.displayContent.tpl.php [8]未定义的索引:avisnote通知àlaligne 30 du fichier C:\ xampp2 \ htdocs中\ projet_presta \程序\缓存\ dev的\智者\编译\ 86 \ 1C \ 1C \ 861c1cb1906b13002a1460e54203e8a370598366.file.displayContent.tpl.php [8]试图获得非对象的属性
在我的模块avisnote.php
文件中:
public function displayContent()
{
$avisnote = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'avisnote` LIMIT 1');
print_r($avisnote);
foreach ($avisnote as $row)
{
$file = $row['url'];
$state = $row['etat'];
}
if(isset($fileContent) && !empty($fileContent))
{
$fileContent = file_get_contents($file, NULL, NULL);
$var_sep = explode(";", $fileContent);
$nb_avis = $var_sep[0];
$note = $var_sep[1];
$this->context->$smarty->assign('avisnote',
array('nb_avis' => $nb_avis,
'note'=>$note,
'etat'=>$state));
}
return $this->display(__FILE__,'views/templates/hook/displayContent.tpl');
}
我的文件路径:
displayContent.tpl:
<p></p>
<div itemprop="itemreviewed" itemscope="" itemtype="http://data-vocabulary.org/Review-aggregate">
<span itemprop="itemreviewed">Mywebsite</span> <span itemprop="rating" itemscope="" itemtype="http://data-vocabulary.org/Rating"> <span itemprop="average">{$avisnote.note}</span> sur <span itemprop="best">5</span> </span>
<br />basé sur <span itemprop="votes">{$avisnote.nb_avis}</span> avis Avis Vérifiés</div>
</div>
答案 0 :(得分:0)
您的代码中至少有2个错误。
首先检查是否isset($ fileContent)然后使用变量$ file。其次,你有$ this-&gt; context-&gt; $ smarty ...你修改的代码应该更像:
public function displayContent()
{
$avisnote = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'avisnote` LIMIT 1');
print_r($avisnote);
foreach ($avisnote as $row)
{
$file = $row['url'];
$state = $row['etat'];
}
$nb_avis = $note = $state = '';
if(isset($file) && !empty($file))
{
$fileContent = file_get_contents($file, NULL, NULL);
$var_sep = explode(";", $fileContent);
$nb_avis = $var_sep[0];
$note = $var_sep[1];
}
$this->context->smarty->assign('avisnote',
array('nb_avis' => $nb_avis,
'note'=>$note,
'etat'=>$state));
return $this->display(__FILE__,'views/templates/hook/displayContent.tpl');
}