2017-12-18 18:23:18 2180次浏览 1条回答 1 悬赏 30 金钱

请教大家,资源包注册AppAsset::register($this);一定要写在layout模板里面吗?我写好了资源包,但是我的视图不需要模板,所以我在控制器中使用$this->renderPartial()渲染视图,然后在视图文件中使用AppAsset::register($this);注册资源包,但是不生效,郁闷。。。有哪位同学可以帮我解答一下吗?感谢。

  • 回答于 2017-12-21 09:59 举报

    视图源码呢? 贴出来看看

    猜测应该是你的视图文件不完整,不管你是否需要layout模版。
    使用框架渲染视图,需要符合一定的规范如

    <?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="<?= Yii::$app->language ?>">
    <head>
    <meta charset="<?= Yii::$app->charset ?>">
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
    </head>
    <body>
    <?php $this->beginBody() ?>
    
    <?= $content;//不需要模版时, 替换为 具体视图的代码 ?>
    
    <?php $this->endBody() ?>
    </body>
    </html>
    <?php $this->endPage() ?>
    

    有兴趣研究源码的话,推荐看看 $this->head() 部分的源码

您需要登录后才可以回答。登录 | 立即注册
是啊俊
经理

是啊俊

注册时间:2017-07-28
最后登录:2018-01-23
在线时长:13小时58分
  • 粉丝0
  • 金钱785
  • 威望20
  • 积分1115

热门问题