Include CSS,javascript file in Yii Framework

前端 未结 18 1831
[愿得一人]
[愿得一人] 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:07

    In the view, add the following:

    getClientScript();
      $cs->registerScriptFile('/js/yourscript.js', CClientScript::POS_END);
      $cs->registerCssFile('/css/yourcss.css');
    ?>
    

    Please notice the second parameter when you register the js file, it's the position of your script, when you set it CClientScript::POS_END, you let the HTML renders before the javascript is loaded.

提交回复
热议问题