2017-02-02 110 views
1

嗨,我是新來prestashop,我嘗試創建一個管理模塊1.7。 我會創建一個新菜單來顯示一個模板並管理我的數據庫。Prestashop 1.7創建管理模塊

模塊/ 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; 
    } 
} 

模塊/ MyModule的/控制器/管理/ 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版本上找不到真正有用的互聯網。

任何幫助/建議嗎?

感謝

EDIT1:OK,安裝是否正確,創建我的標籤,但是當我點擊它它稱爲「控制器= MyModule的」和模塊控制器找不到。就快結束了。

+0

您不會從'install()'方法返回true或false。 – TheDrot

+0

@TheDrot謝謝,現在安裝沒有返回錯誤,但我的菜單也不顯示。 –

+0

您是否收到任何錯誤? – TheDrot

回答

1

模塊的install()方法必須返回true/false。

至於模板裝載從ModuleAdminController

$this->createTemplate($template); 

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

  1. /current_theme /模塊/ yourmodule /視圖/模板/管理/
  2. /modules/yourmodule/views/templates/admin/

因此,如果您使用路徑將createTemplate()稱爲附加到上述兩個文件夾中的任意一個,並且它找不到您的模板並且會拋出錯誤。

將您的模板移動到modules/yourmodule/views/templates/admin/,並調用只有模板名稱的create方法。

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

謝謝,我也添加我的控制器到我的模塊的方式,你告訴我添加我的模板:module/mymodule/controller/admin/MymoduleController.php。但沒有找到。 –

+0

「控制器」,而不是「控制器」......我的幫助不好謝謝! –

1

看起來你的模塊的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; 
    }