将模块的数据库 table 中的数据显示到 Prestashop 产品页面 - Prestashop 1.7.7.6

Display Data from database table of module to Prestashop Product Page - Prestashop 1.7.7.6

我在互联网上找到一个 CRUD 模块(创建、读取、更新、删除),它在 Prestashop 1.7.7.6 的后台工作得很好

现在我想 select 来自模块 table 的数据并显示在前台 prestashop 产品页面 tpl 文件中

我该怎么办?

请帮帮我

非常感谢您

crud 模块 moduletest 的结构:

- Classes / Moduletesttabletest.php
- Controllers / Admin / Adminmoduletest.php
- moduletest.php

将模块的数据库 table 中的数据显示到 Prestashop 产品页面 - Prestashop 1.7.7.6

需要select挂钩才会显示数据

然后将此挂钩添加到您的 moduletest.php 文件的两个位置。
例如,要在价格块附近的产品页面上显示数据,您可以使用钩子 ProductPriceBlock

  1. 您的模块中有 public 函数 install()。它会注册 hook,所以 prestashop 知道它的函数需要被调用

      public function install()
     {    ....
         $this->registerHook('header') &&
         $this->registerHook('backOfficeHeader') &&
       ++$this->registerHook('displayProductPriceBlock');
     }
    
  2. 在关闭代码块“}”之前的文件末尾添加代码以根据函数检索和显示数据:

 public function hookdisplayProductPriceBlock($params)
 {    //     your code goes here         }
  1. 在模块模块管理器中重置模块 - 这实际上会在您更改源代码后注册挂钩

  2. 要使用模版你需要根据模块的/views/templates/front/子目录下的tpl文件并通过

    调用它
     $this->display(__FILE__, 'my-template.tpl');