#How does the Yii framework reference JS and CSS files?
First put the CSS and JS files in the web directory; then open the "AppAsset.php" file and rewrite the "registerAssetFiles" method; then change the CSS and JS file paths in this method Register; finally call the parent method.
Sample code
<?php /** * @link http://www.yiiframework.com/ * @license http://www.yiiframework.com/license/ */ namespace app\assets; use yii\web\AssetBundle; class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; // public $css = [ // 'css/site.css', // 'bootstrap/css/bootstrap.min.css', // ]; // public $js = [ // 'jquery/jquery.min.js', // 'bootstrap/js/bootstrap.min.js' // ]; public function registerAssetFiles( $view ) { //加一个版本号 //目的:使浏览器获取最新的文件 $release = "20200526"; $this->css = [ "bootstrap/css/bootstrap.min.css?v={$release}" ]; $this->js = [ 'jquery/jquery.min.js', 'bootstrap/js/bootstrap.min.js' ]; parent::registerAssetFiles( $view ); } }
Recommended tutorial: "Yii Tutorial"
The above is the detailed content of How does the Yii framework reference JS and CSS files?. For more information, please follow other related articles on the PHP Chinese website!