2017-02-02 11 views
1

こんにちは、私はprestashopを初めて使いました。私は1.7への管理モジュールを作成しようとしています。 私は、テンプレートを表示し、私のDBを管理するための新しいメニューを作成します。Prestashop 1.7 create admin module

モジュール/ 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は、最初のモジュールを作成するためのドキュメントを提供していますが、実際には文書化されていません。

ヘルプ/提案はありますか?

おかげ

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()にパスを指定すると、上記の2つのフォルダのいずれかに追加され、テンプレートが見つからず、エラーがスローされます。

テンプレートを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; 
    } 
関連する問題