致命错误:在非对象代码点火器$ query-> num_rows()== 1)上调用成员函数where() [英] Fatal error: Call to a member function where() on a non-object codeigniter $query->num_rows()==1)
问题描述
Possible Duplicate:
CodeIgniter - Call to a member function select() on a non-object
我是Codeigniter的新手,遇到了一些问题.
I'm newbie with codeigniter and have some problems.
错误消息: 致命错误:在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;
}
}
}
请寻求帮助
推荐答案
$this->db
似乎未定义.似乎您的模型中没有属性名称$db
.
$this->db
seems not to be defined. Seems you dont have a property names $db
within your Model.
您是否使用过:$this->load->database();
初始化数据库?
Have you used: $this->load->database();
to initialize your database?
尝试以下代码:
class Model_users extends CI_Model {
function __construct(){
parent::__construct();
$this->load->database();
}
信息
示例: http://maestric.com/doc/php/codeigniter_models
用户指南: http://ellislab.com/codeigniter/user_guide/database/examples.html
Information
Example: http://maestric.com/doc/php/codeigniter_models
User Guide: http://ellislab.com/codeigniter/user_guide/database/examples.html
这篇关于致命错误:在非对象代码点火器$ query-> num_rows()== 1)上调用成员函数where()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!