We are releasing our RSS datasource to CakePHP developers for CakePHP Development. We know there are others out there, but what we like about ours is that it supports the following:
Download rss_source.php here
Steps to using this datasource:
var $googleNews = array(
'datasource' => 'rss',
'feedUrl' => 'http://news.google.com/news?pz=1&ned=us&hl=en&output=rss',
'encoding' => 'UTF-8',
'cacheTime' => '+1 day',
);
<?php class GoogleNews extends AppModel {
var $useTable = false;
var $useDbConfig = 'googleNews';
}
?>
class NewsController extends AppController {
var $name = 'News';
var $uses = array('GoogleNews');
function index() {
$this->paginate = array(
'limit' => 2,
'conditions' => array(
'title' => '/(Obama)+/',
),
'order' => array(
'GoogleNews.pubDate' => 'desc',
),
);
$this->set('news', $this->paginate('GoogleNews') );
}
}
<?php foreach( $news as $newsItem ) : ?>
<?php echo $html->link($newsItem['GoogleNews']['title'], $newsItem['GoogleNews']['link']); ?>
<?php echo $newsItem['GoogleNews']['pubDate']; ?>
<?php endforeach; ?>
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
And there you have it. Easy RSS via CakePHP.
Share This