我开发了一个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'); }更多推荐
发布评论