Creating RSS Feeds in Codeigniter
Creating an RSS Feed with Codeigniter is our discussion this time.
Every website should have an RSS Feed, this is useful so that other people can take the news that is on our website to be displayed on their website, the content can be entire articles, or only pieces of articles.
In addition to being displayed on visitors’ websites, RSS Feeds are also useful if website visitors want to subscribe to the latest articles from our website through Google Reader, or applications on their cellphones.
rsss
If we use a CMS such as WordPress, Drupal or Joomla, usually the RSS Feed is already available, an example for our favorite website is the RSS Feed address
However, if we create a website without the help of the CMS that we mentioned above, then we must generate the RSS Feed manually.
We assume we create a website using the Codeigniter Framework (we assume you already understand the basics of MVC in Codeigniter), then the steps are something like this:
We take a few articles in our posting table, usually 10 articles are enough. We load the article in the model, then we parse the data from the Controller to the View in XML (not HTML). Examples are as follows.
Creating Databases and Tables
Create a database with the name you want, then create a table with the name tbl_posts, the structure is as follows:
CREATE TABLE tbl_posts
(post_id
int(5) NOT NULL AUTO_INCREMENT,post_title
varchar(100) NOT NULL,slug
varchar(255) NOT NULL,post_content
longtext NOT NULL,post_img
varchar(100) NOT NULL,post_date
datetime NOT NULL,click
int(10) NOT NULL,
PRIMARY KEY(post_id
)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Enter some data, in this example you should enter 10 sample articles, you can also try the SQL file that we have prepared, the file that you can download at the end of this article
Create Controller (rss.php)
<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
class Rss extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->helper(array(‘xml’,’text’));
$this->load->model(‘mdl_rss’);
Create Model (mdl_rss.php)
<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
class mdl_rss extends MY_Model
{
public function __construct()
{
parent::__construct();
}
Create View (rss.php)
‘ . “n”;
?>
<?php echo $feed_name; ?> THEMEPATH?>THEME?>/assets/img/logo-75.png
Copyright
<?php echo $row->post_title; ?>
slug); ?>
slug); ?>
post_date));?>
post_content;?> ]]>
Then later the results will be formed like the RSS Feed on our website. Almost every website has this RSS Feed, especially news websites.
Okay, please download and run it on your codeigniter. Put the model, view