Friday, 30 December 2016

php - CodeIgniter Call to a member function get_where() on a non-object

Im super new to codeigniter and am trying to figure out how to use the Models, ive used a MVP framework before but it was a bit different. I have the users controller, which initializes the model(I think I did it right), then the model has a function, that gets a row by email.



The controller looks like:



class Users extends CI_Controller{
public function login(){

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

$this->users_model->login('slavigne@uark.edu', 'abcdefg');

$this->load->view('templates/header');
$this->load->view('users/login');
$this->load->view('templates/footer');
}
}



and the model looks like:



class users_model extends CI_Model{
public function users_model(){
parent::__construct();
}

public function login($email, $password){
$query = $this->db->get_where('users', array('email' => $email));

return $query->result();
}
}


The problem im getting is:



Call to a member function get_where() on a non-object



which I understand means that db isn't an object, but all the code I saw for models, say that this should work. Any help or advice would be great! Also any advice on newbie mistakes to codeigniter would be nice!

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...