Prestashop 管理模块 tpl 问题

Prestashop admin module tpl issue

我正在进行 prestashop 自定义模块开发,我的想法是创建一个自定义导出模块,我能够安装该模块并在目录菜单下添加菜单。唯一的问题是安装 tpl 文件时没有复制到管理模板文件夹? 我们应该在模块的安装部分使用复制方法复制这些视图吗?

在我的控制器中,我正在尝试从

加载 tpl 文件
public function initContent() {
        parent::initContent();
        $smarty = $this->context->smarty;
        $smarty->assign('test', 'test1');
        $this->setTemplate('wwmexport/wwmexport.tpl');


    }

模块安装后此路径文件不存在 $this->setTemplate('wwmexport/wwmexport.tpl'); 当我手动创建它时一切正常。

我需要知道是否有任何选项可以从我的模块路径加载 tpl,如下所示。

return $this->display(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');

但这不起作用:(

我的模块结构如下

wwmexport
  controllers
    admin
     Adminwwmcontroller.php
  views
    templates
      admin
          wwmexport.tpl

  wwmexport.php

控制器文件有

class AdminWwmExportController extends AdminController {

    protected $module;

    public function __construct() {

        parent::__construct();

    }

    public function display() {

        parent::display();

    }


    public function initContent() {

        if (Tools::getValue('method') != "") {
            $method = Tools::getValue('method');
            $this->$method();
        }

        parent::initContent();
        /*$smarty = $this->context->smarty;
        $smarty->assign(array('test', 'test1'));*/
        //$this->setTemplate('wwmexport.tpl');
        global $smarty;
        $smarty->display(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');

    }
}

我的模块文件wwmexport.php如下。

class WwmExport extends Module {

    public function __construct() {
        $this->name = 'wwmexport';
        $this->tab = 'export';
        $this->version = '1.0.0';
        $this->author = 'Jobin Jose';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Export');
        $this->description = $this->l('Custom Export Features for Products');
        $this->confirmUninstall = $this->l('Are you sure you would like to uninstall?');
    }

    public function install($delete_params = true) {

        if (!parent::install()
            /*|| !copy(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl', _PS_ADMIN_DIR_ . '/themes/default/template/wwmexport.tpl')*/
            || !$this->installModuleTab('AdminWwmExport', array(1 => 'Product Export'), 9)
        ) {
            return false;
        }

        return true;
    }

    public function uninstall() {
        if (!parent::uninstall()
            || !$this->uninstallModuleTab('AdminWwmExport')) {
            return false;
        }

        return true;
    }

    private function installModuleTab($tabClass, $tabName, $idTabParent) {
        $tab = new Tab();

        $tab->name = $tabName;

        $tab->class_name = $tabClass;

        $tab->module = $this->name;

        $tab->id_parent = $idTabParent;

        if (!$tab->save()) {
            return false;
        }

        return true;

    }

    private function uninstallModuleTab($tabClass) {
        $idTab = Tab::getIdFromClassName($tabClass);

        if ($idTab != 0) {

            $tab = new Tab($idTab);

            $tab->delete();

            return true;

        }

        return false;

    }

}

已解决

重写 initContent() 如下。

public function initContent() {    

        parent::initContent();
        $smarty = $this->context->smarty;
        $content = $smarty->fetch(_PS_MODULE_DIR_ . 'wwmexport/views/templates/admin/wwmexport.tpl');
        $this->context->smarty->assign(array('content' => $this->content . $content));

    } 

所以它适合我

$this->display(__FILE__ , 'views/templates/admin/wwmexport.tpl');