2017-07-27 116 views
0

我正在學習編寫模塊到prestashop 1.7,目前我試圖加載用戶嘗試配置模塊時將使用的css和js文件。試圖加載js和css文件在prestashop 1.7管理模塊

這是我模塊的代碼:

class TuxInModComments extends Module 
{ 

    function __construct() 
    { 
     $this->name = 'tuxinmodcomments'; 
     $this->tab = 'quick_bulk_update'; 
     $this->version = '0.1'; 
     $this->author = 'Kfir Ozer'; 
     $this->displayName = 'Tux-In Comments and Ranks'; 
     $this->description = 'With this module, your costumers will be able to grade and comment your products'; 
     $this->bootstrap = true; 

     parent::__construct(); 
    } 

    public function install() { 
     parent::install(); 
     $this->registerHook('actionAdminControllerSetMedia'); 
     return true; 
    } 

    public function processConfiguration() 
    { 
     if (Tools::isSubmit('mymod_pc_form')) { 
      $enable_grades = Tools::getValue('enable_grades'); 
      $enable_comements = Tools::getValue('enable_comments'); 
      $csvFile = Tools::getValue('csv_file'); 
      die(var_export($csvFile)); 
      Configuration::updateValue('MYMOD_GRADES', $enable_grades); 
      Configuration::updateValue('MYMOD_COMMENTS', $enable_comements); 
      $this->context->smarty->assign('confirmation', 'ok'); 
     } 
    } 

    public function assignConfiguration() 
    { 
     $enable_grades = Configuration::get('MYMOD_GRADES'); 
     $enable_comments = Configuration::get('MYMOD_COMMENTS'); 
     $this->context->smarty->assign('enable_grades', $enable_grades); 
     $this->context->smarty->assign('enable_comments', $enable_comments); 
    } 

    public function hookActionAdminControllerSetMedia($params){ 
     $this->registerStylesheet('module-tuxinmodcomments-css','modules/tuxinmodcomments/js/getcontent.css'); 
     $this->registerJavascript('module-tuxinmodcomments-js','modules/tuxinmodcomments/js/getcontent.js'); 
    } 


    public function getContent() { 
     $this->processConfiguration(); 
     $this->assignConfiguration(); 
     return $this->display(__FILE__,'getContent.tpl'); 
    } 

} 

所以我註冊了一個名爲actionAdminControllerSetMedia管理員組媒體鉤,但它似乎不具備的功能設置樣式表和javascript因爲我得到兩者的相同錯誤:Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "registerStylesheet" OR "registerJavascript" of class "AdminModulesController"

我真的很新這個..我讀過,我需要將它設置在前端控制器..但這並不意味着它會出現在常規頁面,而不是在配置頁面?

不知道如何解決這個問題,有點困惑,所以關於這個問題的任何信息將不勝感激。

回答

2

要加載CSS或JS你有恩用這個鉤子,在這個片段:

public function hookDisplayBackOfficeHeader() 
{ 
    $this->context->controller->addCSS($this->_path.'pathtocss/module.css', 'all'); 
    $this->context->controller->addJS($this->_path.'pathtojs/module.js', 'all'); 
} 

享受:)

PS:您必須先註冊顯示後臺頭鉤第一