Tutorial for Codeigniter v3.1.3 and HMVC Pattern
Hi guys, its been 3years since i wrote this tutorial on how to create HMVC pattern using Codeigniter 2.1.4. You may check my old post for that.
Tutorial for HMVC Pattern Codeigniter PHP Framework
Due to insistent public demand, i decided to create a tutorial on how we can use HMVC pattern for Codeigniter 3.1.3
So for new developers that will just start to learn codeigniter, then this is a good start for you.
Intro: Why Codeigniter?
CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.
Framework Features:
- Framework with a small footprint
- Clear documentation
- Compatibility with standard hosting
- No restrictive coding rules
- Simple solutions over complexity
- Exceptional performance
- No large-scale monolithic libraries
- Nearly zero configuration
- No need for template language
- Spend more time away from the computer
Tutorials Data:
- Download CodeIgniter 3.1.3 with hmvc included: Download CodeIgniter with hmvc
Let’s Start
STEP 1
- Download the latest version of codeigniter from their site link here. or you can download my codeigniter here. Fresh CodeIgniter3.1.3.zip
- Download the HMVC Modular Extension from Wiredesignz
STEP 2
- Open up your xampp/wamp (windows) or mamp (mac), then put your downloaded codeigniter 3.1.3 in your htdocs.. Once you view it in your browser you should see a welcome page, see the image below.
- Go to wiredesignz folder that you downloaded a while ago and inside of that folder you will see two folders and files inside.
STEP 3
- We need to copy the core folder files inside of our codeigniter folder in this path: /application/core/ . See the image below.
- Then, we need to copy the third_party folder inside of wiredesignz downloaded folder and copy to application/third_party folder . See the image below.
- Copy MX folder
- Paste it inside codeigniter application third_party folder.

- Then try to browse your localhost codeigniter. You will see that its still running properly.
- And we’re done.
Question?
I encounter this error, when browsing the index page of codeigniter. what should i do?

Error Message
Call to undefined method MY_Loader::ci_object_to_array()
My Face be Like?
Solution
Open up your /application/third_party/MX/Loader.php and find this line.

1 |
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); |
and changed to

1 |
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)); |
AND THATS IT, RUN AGAIN YOUR CODEIGNITER APPLICATION.
Implement HMVC Pattern.
- Create new folder inside of your application, and named it “modules“. then you can create users module that will handle all about users login, profile, transaction etc.
- To access your first hmvc module in codeigniter, open up your xampp/wamp (windows) or mamp (mac). In my case,
1http://localhost/codeigniter-3-hmvc/index.php/users
If you want to access my old tutorial for codeigniter 2.1.4 you may visit this post Tutorial for HMVC Pattern Codeigniter PHP Framework
Thanks man,
Got the error after upgrading to CI 3.1.3 and your tutorial worked
Sure no problem..