how load model in another modules in hmvc in codeigniter? how load model in another modules in hmvc in codeigniter? codeigniter codeigniter

how load model in another modules in hmvc in codeigniter?


$this->load->model("module01/models01");

You can call any models from any module like this. Tested.


add module name followed by model name, make sure every word is in small.I resolved my issue by using this piece of code.

$this->load->model('settings/settings_model','settings_model');


In my case using $this->load->model("module01/models01"); not worked,

But after debugging for couple of hours i have found the solution which is as below, i will explain it using the same example as Questioner:

So the solution not working in my case because i have module name as Module01 (first letter was capital in my directory name) and even if i use the same while loading model like $this->load->model("Module01/models01"); it wasn't working.

Then after trying lots of different cases i have found the solution that worked and want to share some of the rule which we have to follow if we are working in hmvc in codeigniter and loading multiple models in one controller which are as follows:

  • Names of the Directories in modules folder must be in lowercase (should be like module01 not Module01.)

  • The 1st letter of the controller and model files name have to be the uppercase like Module01 and Models01(see below example).

  • The 1st letter of the class name of the controller and model must be in uppercase like

    // module01/Module01.phpclass Module01 extends MX_Controller {   //some code}// module01/Models01.phpclass Models01 extends CI_Model {   //some code}