2017-06-27 35 views
0

我有Prestashop 1.6。在类/ Product.php有例如功能:如何在prestashop tpl文件中调用函数

  • getImages
  • getFeatures

我想从getImages功能在我的TPL文件返回日期。怎么做 ?下面我写这个函数的所有代码:

/** 
* Get product images and legends 
* 
* @param int $id_lang Language id for multilingual legends 
* @return array Product images and legends 
*/ 
public function getImages($id_lang, Context $context = null) 
{ 
    return Db::getInstance()->executeS(' 
     SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position` 
     FROM `'._DB_PREFIX_.'image` i 
     '.Shop::addSqlAssociation('image', 'i').' 
     LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') 
     WHERE i.`id_product` = '.(int)$this->id.' 
     ORDER BY `position`' 
    ); 
} 

感谢您的帮助。亲切的问候。

+0

没有日期字段我图像表 –

回答

1

以下的例子:与的Prestashop是基于MVC架构,现在您有:

  • 模型 - > Product.php,这里是选择你所需要的值的功能。
  • 视图 - > TPL文件是你想要显示这个值。

因此,您需要Controller,负责从模型接收数据,准备它(如果有必要)并将此数据发送到模板。

然后,您现在需要转到控制器/前台文件夹中的ProductController.php。

在控制器中我们有一个名为initContent()的函数,它的功能是创建并将值分配给要在模板中使用的变量。

所以,你需要创建这样一个新的任务:

$this->context->smarty->assign('images_ex', $this->product->getImages((int)$this->context->cookie->id_lang)); 

现在你可以使用这个变量{$ images_ex}在product.tpl,就是在启动主题根文件夹。

希望它可以帮助你。

相关问题