phpcodeigniter-3codeigniter-hmvc

Codeigniter HMVC: Undefined property $db in model


Here is the folder structure in modules folder

  1. users->controllers->Users.php

    users->models->Test_model.php

  2. welcome->controllers->Welcome.php

Test_model.php

class Test_model extends CI_Model {

 function __construct() {
    parent::__construct();
}

public function db_example()
{
     return $this->db->get('mir_users')->result();
}
public function test(){
    echo 'test model call';
}

}

and in Welcome.php

class Welcome extends MX_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('users/test_model');
    }
    public function index()
    {
      //this will give the output   
      $this->test_model->test();
     //thiw will throw error
        $this->test_model->db_example();
    }

$this->test_model->test() returns the output but i will get the error in db_example function

Message: Undefined property: Test::$db

In autoload.php

$autoload['libraries'] = array('database');

I am using the latest version of HMVC

Codeigniter version :3.1.0


Solution

  • Finally I found the solution. The problem is not with my code. It's with the HMVC version.

    For codeigniter versions 3.x use this version https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads?tab=branches

    But I used the wrong version.