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');