1. 在 controller 里用 $this->getView() 设置;public function actionIndex() {
$this->getView()->title = 'title ';
$this->getView()->metaTags['keywords'] = 'keywords';
$this->getView()->metaTags['description'] = 'description';
return $this->render('index');
}
2. 在 view 里读取。
<?php echo Html::encode(($this->title ? $this->title . ' - ' : '') . Yii::$app->name); ?>metaTags['description']) ? $this->metaTags['description'] : ''; ?>" />
metaTags['keywords']) ? $this->metaTags['keywords'] : ''; ?>" />