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'] : ''; ?>" /
3.在view里设置title
<?php $this->title = "设置title"; ?>