Create a new file in a folder -> Controller
1 |
/application/controller/sitemap.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Sitemap extends CI_Controller { function __construct(){ parent::__construct(); $this->load->model('sitemap_mod'); } function sitemap() { $data['urlslist'] = $this->sitemap_mod->getURLS(); $this->load->view("sitemap_view",$data); } } |
Create a new file in a folder -> Models
1 |
/application/models/sitemap_mod.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Sitemap_mod extends CI_Model { public function __construct(){ $this->load->database(); } public function getURLS(){ $this->db->select('column'); $query = $this->db->get('links'); return $query->result_array(); } } |
Create a new file in a folder -> Views
1 |
/application/views/sitemap_view.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php echo'<?xml version="1.0" encoding="UTF-8" ?>' ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc><?php echo base_url();?></loc> <priority>1.0</priority> </url> <!-- Your Sitemap --> <?php foreach($urlslist as $url) { ?> <url> <loc><?php echo base_url()."/".$url['articleID']?></loc> <priority>0.5</priority> </url> <?php } ?> </urlset> |
1. Open routes.php in application/config directory.
2. Add the following line to routes
1 |
$route['sitemap\.xml'] = "sitemap/sitemap_view"; |