Posts Tagged ‘RSS’

Zendframework Feed


25 6月
参考:http://www.developer.com/lang/article.php/10924_3807001_1
  1. public function populargamesAction()
  2. {
  3.  
  4.     // Create array to store the RSS feed entries
  5.     $entries = array();
  6.    
  7.     // Retrieve the 25 most popular games
  8.     $game = new Game();
  9.     $rankings = $game->getLatestSalesRanks(25);
  10.    
  11.     // Cycle through the rankings, creating an array storing
  12.     // each, and push the array onto the $entries array
  13.     foreach ($rankings AS $ranking) {
  14.         $entry = array(
  15.           'title'       => "{$ranking->title}
  16.                           ({$ranking->platform})",
  17.           'link'        => "http://www.gamenomad.com/games/
  18.                            {$ranking->asin}",
  19.           'description' => "Sales Rank: #{$ranking->rank}",
  20.         );
  21.         array_push($entries, $entry);
  22.     }
  23.    
  24.     // Create the RSS array
  25.     $rss = array(
  26.       'title'   => 'GameNomad: Popular Games',
  27.       'link'    => 'http://www.gamenomad.com/games/ranks',
  28.       'charset' => 'ISO-8859-1',
  29.       'entries' => $entries
  30.     );
  31.    
  32.     // Import the array
  33.     $feed = Zend_Feed::importArray($rss, 'rss');
  34.    
  35.     // Write the feed to a variable
  36.     $rssFeed = $feed->saveXML();
  37.    
  38.     // Write the feed to a file residing in /public/rss
  39.     $fh = fopen($this->config->feed->popular_games, "w");
  40.     fwrite($fh, $rssFeed);
  41.     fclose($fh);
  42.    
  43. }

貓熊寶寶幼齒園

姜經緯的博客