Simple sitemaps in codeigniter

Creating sitemaps is a bit of a hassle for any site bigger than a couple of pages, especially where a database is involved. While working on a recent project I created a library for codeigniter which allows the simple creation of sitemaps either by manually adding pages which might be appropriate for a blog, or allowing the library to scan controllers and adding all pages defined by methods. Common search engines can also be notified.

A simple example of it in use is shown below:

//if you are using sparks


//assuming a hypothetical posts_model
$posts = $this->posts_model->get_posts();

foreach ($posts AS $post)
$item = array(
'loc' => site_url('blog/' . $post->slug),
'lastmod' => date('c', strtotime($post->last_modified)),
'changefreq' => 'hourly',
'priority' => '0.8'


// file name may change due to compression
$file_name = $this->sitemaps->build('sitemap_blog.xml');

$reponses = $this->sitemaps->ping(site_url($file_name));

You can download the spark from:

Or get the code from my github:

Simple documentation is included and should be self explanatory.

This library is based on work by Philipp Dörner 2010