Yii2设置关键字,描述,标题
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 里读取。
<title><?php echo Html::encode(($this->title ? $this->title . ' - ' : '') . Yii::$app->name); ?></title> <meta name="description" content="<?php echo isset($this->metaTags['description']) ? $this->metaTags['description'] : ''; ?>" /> <meta name="keywords" content="<?php echo isset($this->metaTags['keywords']) ? $this->metaTags['keywords'] : ''; ?>" />