担心在我的模块未定义索引prestashop的后台(Worry in the backoffice of my module undefined index prestashop)

编程入门 行业动态 更新时间:2024-10-23 09:27:26
担心在我的模块未定义索引prestashop的后台(Worry in the backoffice of my module undefined index prestashop)

我开发了一个prestashop模块,当我在模块的后台时,我有很多错误:

注意:请注意,您可以使用以下命令:avisnote注意à la ligne 30 du fichier C:\ xampp2 \ htdocs \ projet_presta \ app \ cache \ dev \ smarty \ compile \ 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'); }

我的文件的路径:

avisnote.php:模块/ avisnote / displayContent.tpl:Modules / avisnote / views / templates / hook /

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>

I developed a prestashop module, when I am in the backoffice of my module, I have many with errors:

Notice à la ligne 30 du fichier C:\xampp2\htdocs\projet_presta\app\cache\dev\smarty\compile\86\1c\1c\861c1cb1906b13002a1460e54203e8a370598366.file.displayContent.tpl.php [8] Undefined index: avisnote Notice à la ligne 30 du fichier C:\xampp2\htdocs\projet_presta\app\cache\dev\smarty\compile\86\1c\1c\861c1cb1906b13002a1460e54203e8a370598366.file.displayContent.tpl.php [8] Trying to get property of non-object

in my module avisnote.php file:

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'); }

the paths of my files:

avisnote.php : Modules/avisnote/ displayContent.tpl : Modules/avisnote/views/templates/hook/

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>

最满意答案

您的代码中至少有2个错误。

首先检查isset($ fileContent),然后使用变量$ file。 其次,你有$ this-> context - > $ 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'); }

You have at least 2 errors in your code.

First you check if isset($fileContent) then use the variable $file. Second, you have $this->context->$smarty ... Your code fixed should be more like:

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'); }

更多推荐

本文发布于:2023-07-04 11:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   模块   索引   担心   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!