How do I manage assets in Yii2?

后端 未结 4 736
你的背包
你的背包 2021-02-05 05:59

For example, I created a new page, and I\'d like to use, for example, backbone.js, custom css file and some collection of images. Where should I declare all this stuff in Yii2?

4条回答
  •  鱼传尺愫
    2021-02-05 06:32

    At first, you should create SomeAsset class in your app/assets/ folder with your new js and css files. You can extend your AppAsset overloading its properties.

    Next use this in SomeController

    use Yii;
    use app\assets\SomeAsset;
    

    and in actionSome like this:

    SomeAsset::register(Yii::$app->view);
    

提交回复
热议问题