前端控制器无法在prestashop 1.7模块上从setMedia加载css和js [英] front controller won't load css and js from setMedia on a prestashop 1.7 module

查看:0
本文介绍了前端控制器无法在prestashop 1.7模块上从setMedia加载css和js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为prestashop 1.7.2.1编写一个prestashop模块。

我用以下代码为我的模块创建了一个前端控制器:

<?php

require_once (__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'php'.
DIRECTORY_SEPARATOR.'TuxInDb.php');

class TuxInModCarTypeCarTypeProductsModuleFrontController extends ModuleFrontController {

    private $tuxDb;

    public function initContent(){
        parent::initContent();
        $productIds = [];
        $this->tuxDb = TuxInDb::getInstance();
        $companyName = Tools::getValue('company_name');
        $modelName = Tools::getValue('model_name');
        $year = Tools::getValue('year');
        $month = Tools::getValue('month');
        $carType = Tools::getValue('car_type');
        $carListCarTypeIds=$this->tuxDb->getCarListCarTypeIds($companyName,$modelName,$carType,$year,$month);
        $productIds = $this->tuxDb->getProductIdsByCarListCarTypeIds($carListCarTypeIds);
        $this->context->smarty->assign('product_ids',$productIds);
        $this->setTemplate('module:tuxinmodcartype/views/templates/front/cartypeproducts.tpl');
    }

    public function setMedia() {
        parent::setMedia();
        $this->registerStylesheet('module-tuxinmodcartype-cartypeproducts-style','modules/'.$this->module->name.'/css/cartypeproducts.css');
        $this->registerJavascript('module-tuxinmodcartype-cartypeproducts-js','modules/'.$this->module->name.'/js/cartypeproducts.js');
    }

}

setMedia()函数中所示,我加载了一个css和js文件。 我甚至在XDEBUG中对它进行了调试,我注意到这些代码行实际上得到了执行,但当我尝试使用以下URL浏览我的前端控制器时:

http://prestashop.dev:8080/index.php?company_name=BMW&model_name=SERIA+1&year=2011&month=1&car_type=5+%D7%93%D7%9C%D7%AA%D7%95%D7%AA+%28%D7%94%D7%90%D7%A6%D7%B3%D7%91%D7%A7%29&fc=module&module=tuxinmodcartype&controller=cartypeproducts&id_lang=1

我检查了Google Chrome浏览器的网络选项卡,注意到我需要的js和css文件没有加载。

有什么想法吗?

我没有看到任何Java脚本错误或php错误(我还在prestashop中启用了DEV)。

推荐答案

这与PrestaShop 1.7.x配合良好

将此代码添加到您的ModuleFrontController中:

public function setMedia()
{
    parent::setMedia();
    $this->addCSS($this->module->getPathUri().'views/css/style.css');
}

我希望这会有帮助!

这篇关于前端控制器无法在prestashop 1.7模块上从setMedia加载css和js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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