Create RSS using cakephp
It is easy to add RSS into your website using cakephp. Cakephp has a built in library to code or create a RSS output to your visitor. For you that doesn’t know yet RSS, it is a web 3.0 capability to communicate between two website about new update on one website. Its stand for Really Simple Syndication. The purpose isĀ to give a standard output about new change on your website. For example a blog can have RSS to publish their latest post or article.
i will explain a method to add RSS capability into your cakephp website. In this example we have posts controller for our blog post and we want to create RSS for post table. The rss url will look like this
http://www.yoursite.com/posts/rss or change routing for http://www.yoursite.com/rss into posts controller and rss action.
The implementation will explain in 4 step, so here we are
- open app/config/routes.php, add this line and then save
Router::connect(‘/rss’, array(‘controller’ => ‘posts’, ‘action’ => ‘rss’)); - open app/controller/posts_controller.php and create new method or action
function rss(){
$this->set(‘posts’, $this->paginate(‘Post’));
} - create app/views/posts/rss.ctp, and paste this lines
<?php
echo $rss->items($posts, ‘transformRSS’);
function transformRSS($post) {
return array(
‘title’ => $post[‘Post’][‘title’],
‘link’ => array(‘action’ => ‘show’, $post[‘Post’][‘id’]),
‘guid’ => array(‘action’ => ‘show’, $post[‘Post’][‘id’]),
‘description’ => $post[‘Post’][‘text’],
‘author’ => $post[‘User’][‘username’],
‘pubDate’ => $post[‘Post’][‘created’]
);
}
?> - at this point your RSS is ready. check by open URL http://www.yoursite.com/posts/rss or http://www.yoursite.com/rss
As i said, adding or create rss using cakephp is relatively simple to do.

