addJS 函数不适用于 prestashop 中的管理员 [英] addJS function not working for admin in prestashop

查看:50
本文介绍了addJS 函数不适用于 prestashop 中的管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 backOfficeHeader 钩子使用模块在 prestashop 管理中添加 javascript 文件,但没有任何反应.我的代码如下.

I am trying to add javascript file in prestashop admin using backOfficeHeader hook using a module but nothing happened. My code is given below.

public function install()
{
    if (!parent::install()
        || !$this->registerHook('backOfficeHeader'))
        return false;

    return parent::install() && 
     $this->registerHook('backOfficeHeader');
}

 public function hookBackOfficeHeader() {
   $this->context->controller->addJS(_MODULE_DIR_.$this->module->name.'js/hs_custom.js');
 }

推荐答案

如果您使用的是 PS 1.5 或 1.6,您应该使用钩子 "actionAdminControllerSetMedia".

If you are using PS 1.5 or 1.6 you should use hook "actionAdminControllerSetMedia".

您的模块安装程序应检查使用的是哪个 prestashop 版本,然后注册所需的挂钩.

Your module installer should check which prestashop version is used and then register the needed hook.

 if (version_compare(substr(_PS_VERSION_, 0, 3), '1.5', '<'))
      $this->registerHook('BackOfficeHeader');
 else
      $this->registerHook('actionAdminControllerSetMedia');

然后你需要在每个钩子上以它的版本格式添加JS:PS>=1.5

Then you need to addJS on each hook in its version format: PS>=1.5

 public function hookActionAdminControllerSetMedia($params) { 
     $this->context->controller->addJS($this->_path.'views/js/hs_custom.js');
 }

PS<=1.4

public function hookBackOfficeHeader($params) { 
    Tools::addJS($this->_path.'views/js/hs_custom.js');
}

这篇关于addJS 函数不适用于 prestashop 中的管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆