We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Difference between #6 and #5 of How to generate Web feed for an application

How to generate Web feed for an application
[Web feed](http://en.wikipedia.org/wiki/Web_feed) is a data format used for
providing users with frequently updated content. In this article, we describe
how to use [Zend_Feed](http://www.zendframework.com/manual/en/zend.feed.html),
an excellent component from [Zend Framework](http://www.zendframework.com) to
generate Web feed for an Yii application. This article can also serve as a
general guide on how to use other components in Zend Framework.

To begin with, we download Zend Framework and extract it to the directory
`protected/vendors/Zend`. Verify the file `protected/vendors/Zend/Feed.php`

Then, in `SiteController` (or another [controller](/doc/guide/basics.controller)
if you like) create a `feed` action as follows,


public function actionFeed()
	// retrieve the latest 20 posts
		'order'=>'createTime DESC',
	// convert to the format needed by Zend_Feed
	foreach($posts as $post)
	// generate and render RSS feed
		'title'   => 'My Post Feed',
		'link'    => $this->createUrl(''),
		'charset' => 'UTF-8',
		'entries' => $entries,		
	), 'rss');

To this end, the feed is done and we can access it via the following URL:


Using the [URL management](/doc/guide/topics.url) feature of Yii, we can
beautify the above URL to something like `http://www.example.com/feed.xml`.

We can insert this link to the head section of a page using the following code:


We can also use [CHtml::linkTag()] to directly insert the link tag at the
current place in a page. The difference between these approaches is that the
former code can be written anywhere while the latter can only appear in the head
section of a view (or layout).

The [Zend_Feed](http://www.zendframework.com/manual/en/zend.feed.html) component
has many other features. If you are interested, please refer to its


* [Chinese version](http://www.itkuaixun.com/bbs/thread-181-1-1.html
Write new article
  • Written by: qiang
  • Updated by: Yang He
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: +4 / -1
  • Viewed: 26,953 times
  • Created on: Feb 28, 2009
  • Last updated: Jun 29, 2012