Build a RSS 2.0 feed with CodeIgniter?

RSS (Real Simple Syndication) feeds can be found everywhere on the internet. News and information are delivered using it and discussions forums, blogging sites enable usually different types of feeds for their users.

Whenever content defined by the RSS feed changes, feed offers to get an update. As an example, a blogging site could offer types “Full site feed”, “Comments-only feed”, “Label-specific site feed”, “Individual post comment feed”.

Here In this Tutorial, We will build RSS Feed With CodeIgniter Framework

I am assuming that you know basic installation of CI application, if no please have look on CodeIgniter Tutorials

Well, Then Create a CodeIgniter Controller (Class) in Controller folder (applications/controllers/feed.php) called feed.php,

I have commented each and every line just go through the lines

Then its time to create view file , go to views folder it is located at controllers/views, Create a file called
feed_view.php,

Dynamic Rss Feed

We can easily Generate RSS feeds dynamically with very simple Coding.

Create a model Called rss_model.php in controller/model/.

then load this model in our controller with following line

then call the model methods in controllers and pass it to views, see the complete controller

final step make the change in views file , open our view file called feed_view.php

Thank so much !

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
  • EMAD

    IN VIEW FILE PLEASE CHANGE . “n”; IN THE SECOND LINE TO . “n”;

  • Čamo

    Use this gmdate(“r”, $your_date) to create valid rss dates.

  • Nishith Joshi

    I am Getting an error” The URL does not appear to reference a valid XML file. We encountered the following problem: Error on line 2: The processing instruction target matching “[xX][mM][lL]” is not allowed.”
    I am using CI Frame Work.
    Controller:
    public function rssfeed(){
    $this->data[‘feed_name’] = ‘phpis.com’;
    // set page encoding
    $this->data[‘encoding’] = ‘utf-8’;
    // set feed url
    $this->data[‘feed_url’] = ‘http://phpis.com/feed’;
    // set page language
    $this->data[‘page_language’] = ‘en’;
    // set page Description
    $this->data[‘page_description’] = ‘PHP | CodeIgniter | WordPress | MySQL | Css3 | HTML5 | JQuery’;
    // set author email
    $this->data[‘creator_email’] = ‘[email protected]’;
    // this line is very important, this will let browser to display XML format output
    header(“Content-Type: application/rss+xml”);

    $this->data[‘query’] = $this->stModel->getFeedArticles();

    $this->load->view(‘feed_view’,$this->data);
    }
    Model:

    public function getFeedArticles()
    {
    return $this->db->select(‘*’)->from(‘blog’)->where(‘status’,’1′)->get()->result_array();
    }
    view:

    <?php
    echo '’ . “n”;
    ?>

    Copyright

    blog_title; ?>
    slug; ?>
    id; ?>
    blog_desc; ?>

    And when i paste “http://www.edu4sure.com/welcome/rssfeed” as a feed address, i am getting error
    Here Welcome is a name of a controller where as rssfeed is the name of the method

    Request to solve asap, Thanxs in advance