Category Covered

How to make RSS on cakephp

To make RSS feed on cakphp you will be need to follow the steps

1. at first include this two line in controller

    var $helpers = array('Rss');
    var $components = array('RequestHandler');

    2. then make in function in controller
    function rss()
        $news = $this->News->findAll('News.is_active = 1', null, 'News.created DESC', 20);
        $channelData = array(
                'title' =>"RSS News Feed",
                'link' => "http://ugiws:8080/TranslationSite/news/rss.xml",
                'url' => "http://ugiws:8080/TranslationSite/news/rss.xml",
                'description' => "Translation site RSS News Feed" );
       $this->set(compact('channelData', 'articles'));
    3. layout
    in views/rss/default.ctp  /*here rss is the function name and folder name*/
     echo $rss->header();
     $channel = $rss->channel(array(), $channelData, $items);
     echo $rss->document(array(), $channel);

    views\news\rss\rss.ctp  /*news controller name/ rss folder name/ rss.ctp funtion views*/
    function transformRSS($articles)
        return array(
            'title' => $articles['News']['news_titles'],
            'link' => array('controller'=>'news','action' => 'view/'.$articles['News']['id']),
            'guid' => array('controller'=>'news','action' => 'view/'.$articles['News']['id']),
            'description' => strip_tags($articles['News']['news_details']),
            'author' => "Death Penalty Action Network",
            'pubDate' => $articles['News']['created']
    $this->set('items', $rss->items($articles, 'transformRSS'));