Yii2 Assest Bundle在视图中没有加载CSS。

问题描述 投票:0回答:1

我正面临一个问题。我有一个自定义模块,我试图通过AppAsset加载CSS和JS,但它没有加载。

在我的模块中,我有layouts文件夹,我试图访问AppAsset并注册视图,但它没有加载。即使是asset bundle也显示assests正在加载。

告诉我我做错了什么。代码如下

namespace app\assets;

use yii\web\AssetBundle;


class AppAsset extends AssetBundle
{

    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
        'css/bootstrap-reset.css',
        'css/style.css',
        'css/style-responsive.css',
    ];
    public $js = [
        'js/jquery.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}

我的视图文件如下

<?php
use yii\helpers\Html;

use app\assets\AppAsset;

AppAsset::register($this);
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="ThemeBucket">
<link rel="shortcut icon" href="images/favicon.png">

<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>

<!--Core CSS -->



</head>

  <body class="login-body">


    <?php $this->beginBody() ?>

    <?php $this->endBody() ?>
  </body>
</html>

但我根本没有加载CSS,也看不到我在Asset Bundle中定义的任何CSS。

yii2 assets
1个回答
1
投票

功能 <?php $this->head() ?> 只是添加了一个占位符,所有的头部元标签、样式、脚本都必须放在这里。当 <?php $this->endPage() ?> 被调用,它用注册的元标签、样式、脚本等替换占位符。

© www.soinside.com 2019 - 2024. All rights reserved.