簡體   English   中英

Prestashop 1.7創建管理模塊

[英]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); 

嘗試查找模板並加載它找到的第一個模板:

  1. / current_theme /模塊/ yourmodule /視圖/模板/管理/
  2. /模塊/ yourmodule /視圖/模板/管理/

因此,如果您使用路徑調用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM