doushun4666 2017-08-26 07:39
浏览 77

前端控制器不会在prestashop 1.7模块上从setMedia加载css和js

I'm writing a prestashop module for prestashop 1.7.2.1.

I created a front controller for my module with the following code:

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

}

as you can see in setMedia() function I load a css and js files. I even debugged it in xdebug and I noticed that those lines of code actually get executed, but when I try to browse my front controller with the following 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

and I check the network tab of my google chrome browser I noticed that the js and css file I required do not get loaded.

any ideas?

I see no javascript errors or php errors (I also have DEV enabled in prestashop).

  • 写回答

2条回答 默认 最新

  • dswg47377 2017-08-26 08:19
    关注

    If an asset path is wrong then Prestashop won't even append it to the browser's <head> (or bottom depending on CCC settings) and won't throw out any errors.

    Probably your path is incorrect, to get proper path use this:

    $this->registerStylesheet('module-tuxinmodcartype-cartypeproducts-style', $this->module->getPathUri() . 'css/cartypeproducts.css');
    $this->registerJavascript('module-tuxinmodcartype-cartypeproducts-js', $this->module->getPathUri() . 'js/cartypeproducts.js');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100