yii2.0资源管理问题 [ 未指定版本 ]
请教大家,资源包注册AppAsset::register($this);一定要写在layout模板里面吗?我写好了资源包,但是我的视图不需要模板,所以我在控制器中使用$this->renderPartial()渲染视图,然后在视图文件中使用AppAsset::register($this);注册资源包,但是不生效,郁闷。。。有哪位同学可以帮我解答一下吗?感谢。
共 1 个回答
-
视图源码呢? 贴出来看看
猜测应该是你的视图文件不完整,不管你是否需要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分
最后登录:2018-01-23
在线时长:13小时58分
- 粉丝0
- 金钱785
- 威望20
- 积分1115