[英]Prestashop 1.7 create admin module
嗨,我是prestashop的新手,我尝试创建一个1.7的管理模块。 我会创建一个新菜单来显示模板和管理我的数据库。
modules / mymodule / mymodule.php:
<?php
if (!defined('_PS_VERSION_'))
{
exit;
}
class MyModule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'John doe';
$this->bootstrap = true;
parent::__construct();
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->displayName = $this->l('Mon module');
$this->description = $this->l('On test la creation de module presta.');
}
public function install()
{
// Install Tabs
$tab = new Tab();
$tab->active = 1;
$tab->class_name = "MyModule";
$tab->module = 'mymodule';
$tab->name = array();
$tab->id_parent = (int)Tab::getIdFromClassName('SELL');
$tab->position = 3;
foreach ($lang as $l) {
$tab->name[$l['id_lang']] = $this->l('Mon module');
}
$tab->add();
if (!parent::install())
return false;
return true;
}
public function uninstall()
{
// Uninstall Tabs
$tab = new Tab((int)Tab::getIdFromClassName('Mymodule'));
$tab->delete();
// Uninstall Module
if (!parent::uninstall())
return false;
return true;
}
}
module / mymodule / controller / admin / MyModuleController.php:
<?php
class MyModuleController extends ModuleAdminController
{
public function renderList() {
$this->content = $this->createTemplate('mymodule.tpl')->fetch();
return $this->content;
}
}
?>
模块/ mymodule中/视图/模板/管理/ mymodule.tpl:
{block name="page_title"}
{l s='Mon module'}
{/block}
<section >
<div>Hello world !</div>
</section>
我用很多教程1.7 / 1.6的汇编创建了这个,但是安装失败了。 Prestashop为我们提供了一个文档来创建第一个模块,但它并没有真正记录在案,我发现在1.7上没有真正有用的互联网。
任何帮助/建议?
谢谢
编辑1:好的,安装正确,我的选项卡已创建,但当我点击它时,它调用“controller = MyModule”,找不到模块控制器。 就快结束了。
Module的install()
方法必须返回true / false。
至于从ModuleAdminController
加载模板
$this->createTemplate($template);
尝试查找模板并加载它找到的第一个模板:
因此,如果您使用路径调用createTemplate()
,它会附加到上面两个文件夹中的任何一个,并且它找不到您的模板,并且会抛出错误。
将模板移动到modules/yourmodule/views/templates/admin/
,并仅使用模板名称调用create方法。
$this->createTemplate('mymodule.tpl');
似乎模块的install()函数有问题。 您正在注册的钩子似乎也是错误的。 尝试以下代码,它适用于我们:
public function install()
{
if (!parent::install() ||
!$this->registerHook('header')) {
return false;
}
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
$lang = Language::getLanguages();
$tab = new Tab();
$tab->class_name = 'AdminTestimonialSetting';
$tab->module = 'testimonial';
$tab->id_parent = 2;
$tab->position = 6;
foreach ($lang as $l) {
$tab->name[$l['id_lang']] = $this->l('Testimonial');
}
$tab->save();
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.