1

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

shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129

2 Answers2

1

You have loaded database library two times in the autoload and in the model comment this line in model

$this->load->database();
Shibon
  • 1,552
  • 2
  • 9
  • 20
-1

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.

Nicholas Kajoh
  • 1,451
  • 3
  • 19
  • 28
shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129