Prestashop:注意:未定义索引:产品
Prestashop: Notice: Undefined index: produits
我是 prestashop 的新手:我试图在 tpl 文件中显示我的查询结果,但我收到此错误:
Notice: Undefined index: produits
这是我的控制器代码:
class AdminStatproduitController extends ModuleAdminController
{
public function init() {
parent::init();
}
public function initContent()
{
parent::initContent();
$products = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =0
ORDER BY pps.quantity ASC
LIMIT 3');
$pack = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =1
ORDER BY pps.quantity DESC
LIMIT 3');
$smarty = $this->context->smarty;
$content = $smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
$this->context->smarty->assign(array('produits'=>$products,
'pack'=> $pack,
'content' => $this->content . $content));
}
这是我的 tpl 代码
<section>
<div id="formAddPaymentPanel" class="bootstrap panel">
<form id="formAddPayment" method="post">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><span class="title_box ">Id Produit</span></th>
<th><span class="title_box ">Nom Produit </span></th>
<th><span class="title_box ">Quantité Produit</span></th>
<th><span class="title_box ">Pack Choisie</span></th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$produits item=produit}
<tr>
<td>{produit} </td>
<td>product.name</td>
<td>product.quantity</td>
<td>delete</td>
</tr>
</tr>
{/foreach}
</tbody>
</table>
</div>
</form>
</div>
</section>
有什么建议吗??
谢谢
完整代码:
public function initContent()
{
parent::initContent();
$products = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =0
ORDER BY pps.quantity ASC
LIMIT 3');
$pack = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =1
ORDER BY pps.quantity DESC
LIMIT 3');
$this->context->smarty->assign(array('produits'=>$products,
'pack'=> $pack));
$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
}
对于 tpl:
<form id="formAddPayment" method="post">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><span class="title_box ">Id Produit</span></th>
<th><span class="title_box ">Nom Produit </span></th>
<th><span class="title_box ">Quantité Produit</span></th>
<th><span class="title_box ">Pack Choisie</span></th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$produits item=produit}
<tr>
<td>{$produit.id_product} </td>
<td>{$produit.name}</td>
<td>{$produit.quantity}</td>
<td>delete</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
</form>
只需在控制器中进行更改即可:
$this->context->smarty->assign('produits',$products);
$this->context->smarty->assign('pack',$pack);
$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
$this->context->smarty->assign('content',$this->content . $content);
我是 prestashop 的新手:我试图在 tpl 文件中显示我的查询结果,但我收到此错误:
Notice: Undefined index: produits
这是我的控制器代码:
class AdminStatproduitController extends ModuleAdminController
{
public function init() {
parent::init();
}
public function initContent()
{
parent::initContent();
$products = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =0
ORDER BY pps.quantity ASC
LIMIT 3');
$pack = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =1
ORDER BY pps.quantity DESC
LIMIT 3');
$smarty = $this->context->smarty;
$content = $smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
$this->context->smarty->assign(array('produits'=>$products,
'pack'=> $pack,
'content' => $this->content . $content));
}
这是我的 tpl 代码
<section>
<div id="formAddPaymentPanel" class="bootstrap panel">
<form id="formAddPayment" method="post">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><span class="title_box ">Id Produit</span></th>
<th><span class="title_box ">Nom Produit </span></th>
<th><span class="title_box ">Quantité Produit</span></th>
<th><span class="title_box ">Pack Choisie</span></th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$produits item=produit}
<tr>
<td>{produit} </td>
<td>product.name</td>
<td>product.quantity</td>
<td>delete</td>
</tr>
</tr>
{/foreach}
</tbody>
</table>
</div>
</form>
</div>
</section>
有什么建议吗??
谢谢
完整代码:
public function initContent()
{
parent::initContent();
$products = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =0
ORDER BY pps.quantity ASC
LIMIT 3');
$pack = Db::getInstance()->ExecuteS('SELECT pp.id_product, ppl.name, pps.quantity
FROM `'._DB_PREFIX_.'product` pp
LEFT JOIN '._DB_PREFIX_.'product_sale pps ON pps.id_product = pp.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang ppl ON ppl.id_product = pp.id_product
WHERE pp.cache_is_pack =1
ORDER BY pps.quantity DESC
LIMIT 3');
$this->context->smarty->assign(array('produits'=>$products,
'pack'=> $pack));
$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
}
对于 tpl:
<form id="formAddPayment" method="post">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><span class="title_box ">Id Produit</span></th>
<th><span class="title_box ">Nom Produit </span></th>
<th><span class="title_box ">Quantité Produit</span></th>
<th><span class="title_box ">Pack Choisie</span></th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$produits item=produit}
<tr>
<td>{$produit.id_product} </td>
<td>{$produit.name}</td>
<td>{$produit.quantity}</td>
<td>delete</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
</form>
只需在控制器中进行更改即可:
$this->context->smarty->assign('produits',$products);
$this->context->smarty->assign('pack',$pack);
$content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'statproduit/views/templates/admin/statproduit.tpl');
$this->context->smarty->assign('content',$this->content . $content);