【问题标题】:show data from database in custom page using prestashop使用 prestashop 在自定义页面中显示数据库中的数据
【发布时间】:2016-07-30 11:24:32
【问题描述】:

我创建了一个页面,我想在其中显示来自数据库的列表。我已经按照相同的步骤从这个link 开始工作正常。但问题是我无法从my tpl file 中的数据库循环数据。在tpl 文件中显示列表

 <table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
</table>

请帮帮我。

【问题讨论】:

  • 你用 ? 向我们展示了控制器的内容?
  • 请打开我从这个链接iftakharhasan.wordpress.com/2014/04/05/…复制所有内容的链接。但是在这个链接控制器中没有调用?
  • 你是如何改变CustomPageController.php的内容的?
  • 我是 prestashop 的新手。所以在上面的链接 CustomPageController.php 中没有任何地方。请指导我如何实现我的目标?如果您有其他好的链接或提供一些代码@MatteoEnna

标签: php html prestashop template-engine


【解决方案1】:

在custom-page.php之前:$smarty->display(_PS_THEME_DIR_.'custom-page.tpl');

添加:

$customer = CustomerCore::getCustomers();

$contact =array();

foreach ($customer as $c){
    $id = AddressCore::getFirstCustomerAddressId($c['id_customer']);
    $contact[] = new AddressCore($id);
}

$smarty->smarty->assign(array('contacts'=>$contact));

在 custom-page.tpl 中插入:

<table>
    <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
 </tr>
 {foreach $contacts as $contact}
     <tr>
         <td>{$contact->company}</td>
         <td>{$contact->lastname} {$contact->firstname}</td>
         <td>country</td>
     </tr>
 {/foreach}

【讨论】:

  • 谢谢,我会试试的。那我会通知你的。
猜你喜欢
  • 1970-01-01
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
  • 2017-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多