如何在 Prestashop 1.6 的 AdminCustomersController 中使用 createTemplate

How to use createTemplate in AdminCustomersController in Prestashop 1.6

我创建了一个自定义模块,我想在其中向客户列表添加新选项。默认情况下,用户可以使用选项:查看、编辑或删除。我想添加检查选项。对于此测试,我修改了主控制器 AdminCustomersControllerCore 而没有覆盖。

在\controllers\admin\AdminCustomersController.php

public function displayEraseLink($token = null, $id, $name = null) {
        $tpl = $this->createTemplate(_PS_MODULE_DIR_ . $this->module->name.'/views/templates/admin/list_action_erase.tpl');
        $tpl->assign(array(
            'confirm' => $this->l('Erase all client data') . $name,
            'action' => $this->l('Erase'),
            'id' => $id,
        ));
        return $tpl->fetch();
    }

我想加载位于 modules\my_module\views\templates\admin\list_action_erase.tpl 中的 list_action_erase.tpl。在服务器日志中我看到:

无法加载模板文件'/home/user/domains/domain.com/public_html/admin3640wjafn/themes/default/template//home/user/domains/domain.com/public_html/modules//views/templates/admin/list_action_erase.tpl

如何从其他位置加载视图?

亲切的问候

而不是

$tpl = $this->createTemplate(_PS_MODULE_DIR_ . $this->module->name.'/views/templates/admin/list_action_erase.tpl');

使用

$tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_ . $this->module->name.'/views/templates/admin/list_action_erase.tpl');

$this->createTemplate()AdminController$this->context->smarty->createTemplate() 的包装器,它将查找与文件夹 /adminfolder/themes/default/template/.

相关的模板

使用 $this->context->smarty->createTemplate() 本身,您可以指定模板的绝对路径。