dongling5411 2017-07-27 11:02
浏览 55
已采纳

试图在prestashop 1.7管理模块中加载js和css文件

I'm learning to write modules to prestashop 1.7, currently I'm trying to load css and js files that will be used when the user tried to configure the module.

this is the code of my module:

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');
    }

}

so I registered the admin set Media hook with the name actionAdminControllerSetMedia but it seems that it doesn't have the functions to set stylesheet and javascript cause I get the same error for both: Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "registerStylesheet" OR "registerJavascript" of class "AdminModulesController".

I'm really new to this.. I read that I need to set it in the front controller.. but doesn't that mean that it will appear in the regular page and not in the configuration page?

don't know how to resolve this and a bit confused, so any information regarding the issue would be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • dongshan1959 2017-07-27 11:11
    关注

    To load CSS or JS you have tu use this hook, with this snippet:

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

    Enjoy :)

    PS: You have to register the display backoffice header hook first

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?