Skip to content
July 17, 2010 / Samer Baydoun

RSS Feeds in Zend Framework

This example shows how to output an RSS feed using Zend_Feed component. The example supposes that you have a News class that extends Zend_Db_Table class in your models and you included the Zend_Feed component in your Zend Framework library.

class NewsController extends Zend_Controller_Action

function rssAction()

$table = new News();
//Get the last 10 news.
$rows = $table->fetchAll(null,”sort_order”,10);
//Create an array for our feed
$rss = array();

//Seting up the head information of the rss feed
$rss[‘title’]      = “RSS Title Here”;
$rss[‘link’]       = ‘’;
$rss[‘published’]     = time(); //Set the published date to now
$rss[‘charset’]       = ‘utf-8’;
$rss[‘language’]     = ‘ar-sa’; //for Arabic language
$rss[‘logo’] = “http://path/to/logo.gif”;
$rss[‘entries’]       = array();//Which holds the actual news items

//Looping through the news to add them to the ‘entries’ array.

foreach($rows as $row){

$entry = array(); //Container for the entry before we add it on
$entry[‘title’]     = $row->news_title; //The title of the news
$entry[‘link’]         = “http://url/of/the/news/details/page”;
$entry[‘description’]     = $row->news_brief; //a brief of the news
$entry[‘content’]     = $row->news_details; //details of the news

$rss[‘entries’][]     = $entry;


$rssFeedFromArray = Zend_Feed::importBuilder(new Zend_Feed_Builder($rss), ‘rss’);

//disabling the layout

//printing the rss feed to standard output
print $rssFeedFromArray->saveXML();

//sending the HTTP headers and output the rss feed




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: