Loadsys

LoadStr - A Loadsys Blog

A Web Development Company Specializing In Standard-Based Web Design and the CakePHP Framework.

CakePHP RSS Feed Datasource

June 19th, 2009

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:

  • Built-in Pagination
  • Sorting
  • Content filtering

Download rss_source.php here

Steps to using this datasource:

  • Copy rss_source.php to models/datasources
  • Create config for a feed in config/database.php
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’,
);
  • Create model for the feed
<?php class GoogleNews extends AppModel {
        var $useTable = false;
         var $useDbConfig = 'googleNews';
}
?>
  • In a controller just do $this->GoogleNews->find(’all’) or even use paginate. Conditions are specified as regular expressions.
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') );
        }
}
  • Here is a sample view
<?php foreach( $news as $newsItem ) : ?>
        <?php echo $html->link($newsItem['GoogleNews']['title'], $newsItem['GoogleNews']['link']); ?><br/>
        <em><?php echo $newsItem['GoogleNews']['pubDate']; ?></em>
        <hr>
<?php endforeach; ?>
<div class="paging">
        <?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'));?>
</div>

And there you have it. Easy RSS via CakePHP.

Share This

CakePHP jQuery Ajax Helper (Easy Scriptaculous Replacement)

May 1st, 2009

We created this cakephp ajax helper so we could easily replace Scriptaculous with jQuery without changing the code and still have built-in functionality like pagination working properly.  The helper could still be improved, but we have decided to publicly release it so that CakePHP developers can utilize it for CakePHP Development.

 

Read the rest of this entry »

Share This
Close
E-mail It