好吧,我在 AppAsset 中声明了我所有的 CSS 和 JavaScript 内容,但我无法在前端 View 中显示 css 和 js 链接。这是我的文件:
应用程序/ Assets /AppAsset.php:
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'assets/css/bootstrap.min.css',
'assets/plugins/weather-icon/css/weather-icons.min.css',
...
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
这是我的布局(app/modules/admin/layouts/admin.php):
<?php
use app\assets\AppAsset;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->head() ?>
<?= $this->render('partials/head') ?>
</head>
<body class="tooltips">
<?= $this->render('partials/colour_panel') ?>
<div class="wrapper">
<?= $this->render('partials/top_navbar') ?>
<?= $this->render('partials/left_sidebar') ?>
<?= $this->render('partials/right_sidebar') ?>
<div class="page-content">
<div class="container-fluid">
<?= $content ?>
<?= $this->render('partials/footer') ?>
</div>
</div>
</div>
<?= $this->render('partials/scripts') ?>
</body>
</html>
<?php $this->endPage() ?>
提前致谢!
最佳答案
我有同样的问题。就我而言,布局没有 <?php $this->beginBody() ?>
和 <?php $this->endBody() ?>
里面的部分<body></body>
标签。
应该是这样的:
<body>
<?php $this->beginBody() ?>
<!--content-->
<?php $this->endBody() ?>
</body>
希望它可以帮助某人
关于layout - Yii2 AppAsset 未在布局中生成 css/js 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27831023/