Include CSS,javascript file in Yii Framework

前端 未结 18 1833
[愿得一人]
[愿得一人] 2020-11-29 15:46

How to include a Javascript or CSS file in Yii Framework?

I want to create a page on my site that has a little Javascript application running, so I want to include <

18条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 16:13

    Also, if you want to add module assets both CSS and JS, you can use the following logic. See how you need to indicate the correct path to getPathOfAlias:

    public static function register($file)
    {
        $url = Yii::app()->getAssetManager()->publish(
        Yii::getPathOfAlias('application.modules.shop.assets.css'));
    
        $path = $url . '/' . $file;
        if(strpos($file, 'js') !== false)
            return Yii::app()->clientScript->registerScriptFile($path);
        else if(strpos($file, 'css') !== false)
            return Yii::app()->clientScript->registerCssFile($path);
    
        return $path;
    }
    

    The above code has been taken from GPLed Yii based Webshop app.

提交回复
热议问题