好吧,我在AppAsset中声明了我所有的CSS和JavaScript内容,但是无法使其在前端 View 中显示css和js链接。这是我的文件:

app/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/

10-12 01:38