Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter HMVC:模型中未定义的属性$db_Php_Codeigniter 3_Codeigniter Hmvc - Fatal编程技术网

Php Codeigniter HMVC:模型中未定义的属性$db

Php Codeigniter HMVC:模型中未定义的属性$db,php,codeigniter-3,codeigniter-hmvc,Php,Codeigniter 3,Codeigniter Hmvc,以下是modules文件夹中的文件夹结构 用户->控制器->users.php 用户->模型->测试模型.php 欢迎->控制器->欢迎.php Test_model.php class Welcome extends MX_Controller { public function __construct() { parent::__construct(); $this->load->model('users/test_model')

以下是
modules
文件夹中的文件夹结构

  • 用户->控制器->users.php

    用户->模型->测试模型.php

  • 欢迎->控制器->欢迎.php

  • Test_model.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();
        }
    
    类测试模型扩展了CI模型{

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

    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\u model->test()
    返回输出,但我将在
    db\u example
    函数中得到错误

    Message: Undefined property: Test::$db
    
    autoload.php中

    $autoload['libraries'] = array('database');
    
    我正在使用最新版本的
    HMVC


    Codeigniter版本:3.1.0

    您已经在自动加载和模型注释中加载了两次数据库库

    $this->load->database();
    

    您已经在模型中的“自动加载”和“模型注释”这一行中加载了两次数据库库

    $this->load->database();
    

    最后我找到了解决办法。问题不在于我的代码。这是HMVC版本

    对于codeigniter版本3.x,请使用此版本


    但是我使用了错误的版本。

    最终我找到了解决方案。问题不在于我的代码。这是HMVC版本

    对于codeigniter版本3.x,请使用此版本


    但是我使用了错误的版本。

    模型中有名为users的文件夹吗?没有。
    模型中没有文件夹。
    文件夹$this->load->model('users/test_model');为什么要将用户放在这个语句中?这会从另一个模块加载一个模型在模型中有一个名为users的文件夹吗?不,在
    models
    folder$this->load->model('users/test_model')中没有文件夹;为什么要将用户放入此语句中?这将从另一个模块加载模型