简体   繁体   中英

how load model in another modules in hmvc in codeigniter?

I want to use The Modular Extensions HMVC in my Project like this:

modules  
      module01
            models
                models01.php
            controllers
                controller01.php
            views
                views01.php
      module02
            models
                models01.php
            controllers
                controller01.php
            views
                views01.php
      ‘
      ‘

and i want use 'models01.php' from module01 , is there any way?

$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 1 st letter of the controller and model files name have to be the uppercase like Module01 and Models01 (see below example).

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

    // module01/Module01.php class Module01 extends MX_Controller { //some code } // module01/Models01.php class Models01 extends CI_Model { //some code }
$this->load->model('module/Modelname','alise'); 

Remember 1st Letter should be Capital for the Model Name

$this->load->model("module01/Models01",'models01');
$this->models01->function_name();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM