我正在进行prestashop
自定义模块开发,我的想法是创建一个自定义导出模块,我能够安装模块并在目录菜单下添加菜单。唯一的问题是安装tpl
文件而不是复制到管理模板文件夹?
我们应该在模块的安装部分内用copy方法复制这些视图吗?
在我的控制器中我试图从
加载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));
}
答案 0 :(得分:1)
所以它对我有用
$this->display(__FILE__ , 'views/templates/admin/wwmexport.tpl');