Yii2 AppAsset在布局中不生成css/js链接

Гео*_*ков 8 layout assets yii2

好吧,我在AppAsset中声明了我所有的CSS和JavaScript内容,但我不能让它在前端视图中显示css和js链接.这是我的文件:

应用程序/资产/ 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',
    ];
}
Run Code Online (Sandbox Code Playgroud)

这是我的布局(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() ?>
Run Code Online (Sandbox Code Playgroud)

提前致谢!

MEG*_*l23 9

我有同样的问题.在我的情况下,布局没有<?php $this->beginBody() ?>和标签
<?php $this->endBody() ?>内的部分<body></body>.

它应该是这样的:

<body>
<?php $this->beginBody() ?>
   <!--content-->
<?php $this->endBody() ?>
</body>
Run Code Online (Sandbox Code Playgroud)

希望它对某人有帮助


Mih*_* P. 6

这部分

<?php $this->head() ?>
Run Code Online (Sandbox Code Playgroud)

应该自动将它们复制到头部.您确定您使用的路径是否正确?

public $sourcePath = '@vendor';
public $css = [
    'assets/css/bootstrap.min.css',
Run Code Online (Sandbox Code Playgroud)

意味着你的文件在vendor/assets/css/bootstrap.min.css中找到你确定是对的吗?因为那对我来说不对.