【发布时间】:2012-10-02 13:42:22
【问题描述】:
可能重复:
CodeIgniter - Call to a member function select() on a non-object
我是 codeigniter 的新手,遇到了一些问题。
错误消息: 致命错误:调用 C:\xampp\htdocs\moi\CI\application\models\model_users 中非对象上的成员函数 where()。第12行的php
我的模特:
class Model_users extends CI_Model {
function __construct(){
parent::__construct();
}
public function can_log_in() {
$this->db->where('email', $this->input->post('email'));
$this->db->where('pass', md5($this->input->post('password')));
$query = $this->db->get('users');
if ($query->num_rows()==1) {
return TRUE;
} else {
return FALSE;
}
我的控制器:
class Main extends CI_Controller {
public function index() {
$this->login();
}
//Auslagern der Funktionen
public function login() {
$this->load->view('login');
}
public function login_validation() {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|valid_email|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'password', 'required|md5');
if ($this->form_validation->run()) {
redirect('main/members');
} else {
$this->load->view('login');
}
}
public function username_check() {
$this->load->library('form_validation');
$this->load->model('model_users');
if ($this->model_users->can_log_in()) {
return TRUE;
} else {
$this->form_validation->set_message('username_check', 'incorect User or Passwort.');
return FALSE;
}
}
}
请帮忙
【问题讨论】:
-
显然方法
where被调用在不是对象的东西上。你能向用户展示用户超类吗? -
但在我的配置文件中定义
-
我不知道代码点火器,但错误很明显。
$this->db不是对象。如果您认为如果您从对象的超类请求 db 字段,那么您做错了。 -
我该如何解决这个问题?
-
尝试将
username_check()中的$this->load->model('model_users');行更改为$this->load->model('model_users', '', TRUE);以自动连接到您的数据库
标签: php mysql database codeigniter