CodeIgniter-模型已加载但无法使用? [英] CodeIgniter - Model loaded but can't be used?

查看:103
本文介绍了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');

模型名称区分大小写!

这篇关于CodeIgniter-模型已加载但无法使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆