layout - Yii2 AppAsset 未在布局中生成 css/js 链接

标签 layout assets yii2

好吧,我在 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/

相关文章:

path - 对非模板数据使用 "path"和 "asset"

android - android 上的 openalpr - 配置和运行时数据的路径

php - Yii2迁移问题

mysql - xAxis 类别 Highcharts

CSS 网格全高

css - 如何创建固定标题和 100% 内部容器?

java - 日期时间选择器控件

php - CSS Div % 宽度问题

actionscript-3 - 使用数组嵌入许多图形

html - yii2 事件形式中的 Bootstrap 3 复选框 css 样式