CodeIgniter-模型已加载但无法使用?

问题描述:

好的.所以我正在使用CI的网站上工作.这是我的控制器的结构:

Ok. So I am working on a website using CI. Here is the structure of my controller:

class MY_Controller extends Controller
class User extends MY_Controller
class User_Model

因此,我将User_Model加载到User控制器的构造函数中.我知道它已正确加载,因为我尝试从User_Model打印某些内容,并且效果很好.但是,当我从User控制器使用User_Model中的功能之一时,它开始给我错误.这是我收到的错误:

So, I load the User_Model inside the constructor of the User controller. I know that it is loaded properly because I tried to print something from User_Model and it worked just fine. However, when I use one of the functions in the User_Model from User controller, it started giving me the error. This is the error I received:

未定义的属性:User :: $ User_Model

Undefined property: User::$User_Model

有人有什么主意吗?

这是扩展控制器

class MY_Controller extends Controller {
    public function __construct() {
      parent::Controller();
    }
}

这是控制器

class User extends MY_Controller {
    public function __construct() {
      parent::__construct();
      $this->load->model('user_model');
      echo $this->user_model->validate_user('hartantothio');
    }
}

这是User_model

This is the User_model

class User_model extends Model {
    public function __construct() {
        parent::Model();
    }        
    public function validate_user($user, $pass = '') {
        return '123';
    }
}

$this->load->model('user_model');

应阅读

$this->load->model('User_model');

模型名称区分大小写!