Example HMVC Routing Blog Engine

in codeigniter hmvc, we create every controller to modules …

in my experience, i had made modules content, this module handle all input page html, in simple word it save html code to database and view it in browser

in module content, the content divide by category, you can say category like ‘Blog’, ‘News’, etc

in many development, news have almost same like blog, so you can use controller blog category to view news category

my codeigniter hmvc structure modules content

modules hmvc codeigniter ci controller structure
modules hmvc codeigniter ci controller structure

from the structure, my real url is

and i want to simply it with this
and this

my blog class is

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class blog extends GW_Controller {

	public function __construct(){


	public function index(){
	public function pages($_category = 'news-events', $_pages = false){

		// patch here if you get blank false or zero _pages value
		if(!$_pages) {
			$_pages = $this->uri->segment(2);

		echo 'Your Category:'. $_category;
		echo 'Your Pages:'. $_pages;

		// your code view thumb post + pagging etc

	 * detail content
	 * @param string $_id_uri
	public function view($_id_uri = false){

	// your code view here


and now get the routes

// add this to file routes.php
$route['news-event/:num'] = 'content/blog/pages/news-event$1';

$route['news-event'] = 'content/blog/index/news-event';

news-events its the category  i want to view

more readable url
more readable url


and if you have more category like blogs, events, microsite etc just do it …


Published by


just to remember what i had known :)

One thought on “Example HMVC Routing Blog Engine”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s