how load model in another modules in hmvc in codeigniter?

前端 未结 3 548
逝去的感伤
逝去的感伤 2021-01-18 01:34

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

modules  
      module01
            models
                models01.php
            contr         


        
相关标签:
3条回答
  • 2021-01-18 01:42

    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');
    
    0 讨论(0)
  • 2021-01-18 01:58
    $this->load->model("module01/models01");
    

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

    0 讨论(0)
  • 2021-01-18 01:58

    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.php
      class Module01 extends MX_Controller {
         //some code
      }
      
      // module01/Models01.php
      class Models01 extends CI_Model {
         //some code
      }
      
    0 讨论(0)
提交回复
热议问题