yii2 资源
yii2 资源
AppAsset.php
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
'/js/alert.js'
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap5\BootstrapAsset'
];
}
$css:引入页面的CSS文件 $js:引入页面的JS文件 $depends:引入依赖的前端库
layout全局引用
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" class="h-100">
<head>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body class="d-flex flex-column h-100">
<?php $this->beginBody() ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
引入单页面css
<?php
use yii\helpers\Html;
?>
<?= Html::cssFile('@web/css/test.css') ?>
单页面内引入JS
<?php
use yii\helpers\Html;
?>
<?=Html::jsFile('@web/assets/util.lin.js')?>