简体   繁体   中英

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

您已在自动加载中加载了两次数据库库,并在模型中注释了此行中的这一行

$this->load->database();

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.

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