aya
aya

Reputation: 1613

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?

Upvotes: 8

Views: 9717

Answers (4)

whitehawk321
whitehawk321

Reputation: 9

$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();

Upvotes: 0

Haritsinh Gohil
Haritsinh Gohil

Reputation: 6272

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
    }
    

Upvotes: 0

Muhammad Tahir
Muhammad Tahir

Reputation: 2491

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');

Upvotes: 0

Mansoorkhan Cherupuzha
Mansoorkhan Cherupuzha

Reputation: 1761

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

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

Upvotes: 28

Related Questions