频道栏目
首页 > 资讯 > Yii > 正文

Yii框架中给网页设置keywords和description的方法

16-01-07        来源:[db:作者]  
收藏   我要投稿

If we want to set meta tags on a per page (controller-action) basis, we may use the?clientScript?application component.

Controller

Yii::app()->clientScript->registerMetaTag('This is an example', 'description');

    $this->render('example');

  }

}

?>

This will insert the description meta tag automatically into the layout when the render() function gets called.

Another solution would be to use a parent controller with the property $pageDescription. That way we don't have to make a function-call to set the description. Instead, we can easily modify the description inside of the controller. In the layout-file we'll simply echo the meta tag (if defined).

Parent-Controller

Controller

pageDescription = 'This is an example';

    $this->render('example');

  }

}

?>

Layout


pageDescription))
{
  echo '

Think about this:

$this->pageFeeds[] = 'http://example.com/feeds/recent.xml';
$this->pageFeeds[] = 'http://example.com/feeds/popular.xml';

I hope you enjoyed the read. Feel free to share your thoughts - thank you.

Tip:?Since the two classes?ParentController?and?ExtendedCController?are no real controllers (they only function as parent-classes), you have to put them into the components folder (egprotected/components).

相关TAG标签
上一篇:PHP url参数有关问题
下一篇:PHP下使用fckeditor的方法
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站