在控制器中我有
$this->view = $this->getView();
...
$this->view->registerMetaTag(['name' => 'meta', 'content' => '...']);
$this->view->render();
在视图<?php $this->head() ?>
中只插入资产,没有元:
<link href="/frontend/web/assets/a8c97299/toolbar.css" rel="stylesheet">
...
页面的其余部分显示得很好。
我试图弄清楚在头部插入期间框架中发生了什么。似乎$this->clear();
禁用了元渲染。我已经成功登录
<meta name="meta" content="...">
<link href="/frontend/web/assets/a8c97299/toolbar.css" rel="stylesheet">
...
从那里,并与注释$this->clear();
元呈现在视图中,如预期的
如何解释和修复?
你应该在你的控制器中:
public function actionIndex()
{
'Yii::$app->view->registerMetaTag([
'name' => 'description',
'content' => 'Description of the page...'
]);
return $this->render('index');
}
在布局文件中:
<head>
<?php $this->head() ?>
</head>