错误TPL PHP Prestashop
我正在处理Prestashop,我想从我在数据库中创建的表中检索数据。我已经用了两天了,什么都没用,我会发疯的 下面是我放在ProductController.php文件中的代码:错误TPL PHP Prestashop,php,smarty,prestashop,prestashop-1.7,Php,Smarty,Prestashop,Prestashop 1.7,我正在处理Prestashop,我想从我在数据库中创建的表中检索数据。我已经用了两天了,什么都没用,我会发疯的 下面是我放在ProductController.php文件中的代码: private function GetAvailableAttributes($id_produit, $id_compte, $note) { global $smarty; $sql = 'SELECT id_produit, id_compte, note
private function GetAvailableAttributes($id_produit, $id_compte, $note)
{
global $smarty;
$sql = 'SELECT id_produit, id_compte, note
FROM `'.'ps_product_avis';
$ess=mysql_result($sql,0);
$smarty->assign('contact', $ess);
}
以下是放在product.tpl文件中的代码:
<li>test :{$contact}</li>
测试:{$contact}
下面是它给出的错误:
你们谁能救我一命,解释一下问题出在哪里
我提前感谢您。在PrestaShop 1.7(以及1.5和1.6)中,全局var$smarty
被弃用。
您犯了各种错误,我将尝试用更正来解释:)
在以下位置更改您的代码:
private function GetAvailableAttributes($id_produit, $id_compte, $note)
{
/* global $smarty; DEPRECATED */
$sql = 'SELECT id_produit, id_compte, note
FROM `'._DB_PREFIX_.'product_avis`';
/* Use always _DB_PREFIX_ constant var */
/* $ess=mysql_result($sql,0); Use Db class instead of this old method */
$ess = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
/* $smarty->assign('contact', $ess); Deprecated use */
$this->context->smarty->assign('contact', $ess);
}
记住,执行
方法返回一组数组,如果有一个元素要返回
因此,您的阵列将如下所示:
array(
[0] => array(
'id_produit' => 1,
'id_compte' => 1,
'note' => 'my note'
)
);
在smarty中,要打印单个元素,应执行以下操作:
它将打印我的笔记 仅此而已:)在PrestaShop 1.7(以及1.5和1.6)中,全局var
$smarty
被弃用。
您犯了各种错误,我将尝试用更正来解释:)
在以下位置更改您的代码:
private function GetAvailableAttributes($id_produit, $id_compte, $note)
{
/* global $smarty; DEPRECATED */
$sql = 'SELECT id_produit, id_compte, note
FROM `'._DB_PREFIX_.'product_avis`';
/* Use always _DB_PREFIX_ constant var */
/* $ess=mysql_result($sql,0); Use Db class instead of this old method */
$ess = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
/* $smarty->assign('contact', $ess); Deprecated use */
$this->context->smarty->assign('contact', $ess);
}
记住,执行
方法返回一组数组,如果有一个元素要返回
因此,您的阵列将如下所示:
array(
[0] => array(
'id_produit' => 1,
'id_compte' => 1,
'note' => 'my note'
)
);
在smarty中,要打印单个元素,应执行以下操作:
它将打印我的笔记
仅此而已:)在哪里调用该方法?每个产品页都会调用它。不,我的意思是您在控制器的哪个方法中调用该方法?我不明白。我想在我的所有产品页面中显示我的数据库数据。我想创建一个产品评级区域。好的,让我们从头开始。。。您已经在控制器(即
ProductController.php
)中添加了自定义方法GetAvailableAttributes
),现在该方法调用了ProductController
的哪个部分?该方法在何处调用?它针对每个产品页面调用。否,我的意思是,你们在控制器的哪个方法中调用这个方法?我不明白。我想在我的所有产品页面中显示我的数据库数据。我想创建一个产品评级区域。好的,让我们从头开始。。。您已经在控制器中添加了自定义方法GetAvailableAttributes
(ProductController.php
),现在该方法调用了ProductController
的哪个部分?非常感谢您的回答。我理解您的所有指示,但我有相同的错误:(非常适合php,但当我在TPL中添加{$contact[0]['note']}时,我有一个错误然后查看显示内容。不管您的查询应该如何修改,您都应该添加id_产品,因为该查询会获取数据库中的所有产品。使用此命令: