0
我正在做一个prestashop
自定义模块开发,我的想法是创建一个自定义导出模块,我能够安装该模块并添加目录菜单下的菜单。唯一的问题是安装tpl
文件不复制到管理模板文件夹? 我们是否应该使用复制方法在模块的安装部分复制这些视图?Prestashop管理模块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));
}
感谢您的anwser,但它并没有为我工作。当我把你的代码示例显示空白内容区域,左侧管理菜单显示两次?任何想法 ? –
你的代码在哪里?在模块的主文件中还是在AdminController中?你可以发布你的模块的结构? – Matteo
我刚刚注意到它显示在html标签之前的页面源代码中,当我使用下面的代码'global $ smarty; \t \t $ smarty-> display(_PS_MODULE_DIR_。'wwmexport/views/templates/admin/wwmexport.tpl');' –