Ярлыки

.htaccess (4) тестирование (8) шаблоны проектирования (3) css (5) Debian (6) docker (2) Doctrine2 (6) Git (6) html (4) java (6) javascript (13) jquery (11) LFS (3) linux (23) mac os (4) mod_rewrite (2) MSSQL (4) MySQL (18) ORM Doctrine (17) patterns (3) PDO (3) perl (7) PHP (64) PHPUnit (8) Python (15) SEO (2) Silex (1) SimpleXML (1) SQL (14) ssh (4) Ubuntu (24) Yii1 (1) Zend Framework (19) ZendFramework2 (8)

вторник, 7 февраля 2012 г.

Zend Framework. Создание rss или atom потока.

Форматируем данные
//Create an array for our feed
$feed = array();
 
//Setup some info about our feed
$feed['title']          = "ZendCoding.com's Newest Stories";
 
$feed['link']           = 'http://www.zendcoding.com/newest-stories.rss';
 
$feed['charset']    = 'utf-8';
 
$feed['language']   = 'en-us';
 
$feed['published']  = time();
 
$feed['entries']    = array();//Holds the actual items
 
//Loop through the stories, adding them to the entries array
foreach($stories->fetchAll($select) as $story){
    $entry = array(); //Container for the entry before we add it on
 
    $entry['title']     = $story->title; //The title that will be displayed for the entry
 
    $entry['link']      = $story->url; //The url of the entry
 
    $entry['description']   = $story->teaser; //Short description of the entry
 
    $entry['content']   = $story->description; //Long description of the entry
 
    //Some optional entries, usually the more info you can provide, the better
    $entry['lastUpdate']    = $story->modified; //Unix timestamp of the last modified date
 
    $entry['comments']  = $story->commentsUrl; //Url to the comments page of the entry
 
    $entry['commentsRss']   = $story->commentsRssUrl; //Url of the comments pages rss feed
 
    $feed['entries'][]  = $entry;
}

Импорт в поток
$feedObj = Zend_Feed::importArray($feed, 'rss'); //Or importArray($feed, 'atom');

Вывод
//Return the feed as a string, we're not ready to output yet
$feedString = $feedObj->saveXML();
 
//Or we can output the whole thing, headers and all, with
$feedObj->send();

Комментариев нет:

Отправить комментарий