简体   繁体   English

Prestashop 1.7创建管理模块

[英]Prestashop 1.7 create admin module

Hi i'm new to prestashop and i try to create an admin module to 1.7. 嗨,我是prestashop的新手,我尝试创建一个1.7的管理模块。 I would create a new menu to display a template and manage my DB. 我会创建一个新菜单来显示模板和管理我的数据库。

modules/mymodule/mymodule.php : 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 : module / mymodule / controller / admin / MyModuleController.php:

<?php
class MyModuleController extends ModuleAdminController
{
    public function renderList() {
        $this->content = $this->createTemplate('mymodule.tpl')->fetch();
        return $this->content;
    }
}
?>

modules/mymodule/views/templates/admin/mymodule.tpl: 模块/ mymodule中/视图/模板/管理/ mymodule.tpl:

{block name="page_title"}
    {l s='Mon module'}
{/block}
<section >
    <div>Hello world !</div>
</section>

I create this with a compilation of a lot of tutorials 1.7 / 1.6 but the installation fail. 我用很多教程1.7 / 1.6的汇编创建了这个,但是安装失败了。 Prestashop provide us a documentation to create a first module but it's not really documented and i find nothing really helpfull on internet yet for 1.7. Prestashop为我们提供了一个文档来创建第一个模块,但它并没有真正记录在案,我发现在1.7上没有真正有用的互联网。

Any help/suggestions ? 任何帮助/建议?

Thanks 谢谢

EDIT1 : ok, the install is correct, my tab is created but when i click on it it calls "controller=MyModule" and the module controller is not found. 编辑1:好的,安装正确,我的选项卡已创建,但当我点击它时,它调用“controller = MyModule”,找不到模块控制器。 Almost finished. 就快结束了。

Module's install() method must return a true/false. Module的install()方法必须返回true / false。

As for template loading from ModuleAdminController 至于从ModuleAdminController加载模板

$this->createTemplate($template); 

tries to find template and load the first one it finds in: 尝试查找模板并加载它找到的第一个模板:

  1. /current_theme/modules/yourmodule/views/templates/admin/ / current_theme /模块/ yourmodule /视图/模板/管理/
  2. /modules/yourmodule/views/templates/admin/ /模块/ yourmodule /视图/模板/管理/

So if you call createTemplate() with a path it's appended to either of the two folders above and it doesn't find your template and that throws out an error. 因此,如果您使用路径调用createTemplate() ,它会附加到上面两个文件夹中的任何一个,并且它找不到您的模板,并且会抛出错误。

Move your template into modules/yourmodule/views/templates/admin/ and call create method with only template name. 将模板移动到modules/yourmodule/views/templates/admin/ ,并仅使用模板名称调用create方法。

$this->createTemplate('mymodule.tpl');

It seems that there is something wrong with the install() function of your module. 似乎模块的install()函数有问题。 The hook that you are registering seems wrong as well. 您正在注册的钩子似乎也是错误的。 Try the following code, it worked for us: 尝试以下代码,它适用于我们:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM