阅读

Yii2设置关键字,描述,标题

Yii2  2016-11-29 14:45

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'] : ''; ?>" />


广告

【腾讯云】618云上GO!云服务器限时秒杀,1核2G首年95元!
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。

广告

618优惠礼包限时领取,更有2000元飞天会员礼包等你来拿
上云优惠聚集地,云小站专属代金券可叠加产品折扣使用