[eluser]harpster[/eluser]
Beginners question here - I need to ask for advice after several hours of trying to do what I think should be pretty simple. Maybe my MVC concept is wrong but this is for a user login form that submits to the controller which calls the model for a validate query. After validating the user I want to set the session for the user_id and first_name and I was going to do this in the controller but every way I've tried I get an error, usually
Fatal error: Call to a member function result() on a non-object.
I just can't seem to be able to access the data from the query in the controller but I can do it easily in the model. So I wonder what I'm doing wrong? Maybe it's better to process everything in the model but can't you access that query data in the controller too? Thanks for the help... It's driving me nuts and I really need to get a better understanding of this concept.
MODEL: simplified code - this works and I can access the query results here by adding the
foreach ($query->result() as $row) code.
Code:
function validate()
{
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('users');
if($query->num_rows() > 0)
{
return $query->result();
} else {
echo "not validated"; exit; //msg for for testing only
}
}
[b]CONTROLLER simplified code[b] - get errors
Code:
function validate_user()
{
$this->load->model('users_model');
$query = $this->users_model->validate();
//I'm trying to echo user_id & first_name as a test but get errors. This is where I'll be setting the session.
foreach ($query->result() as $row)
{
echo $row->user_id;
echo $row->first_name;
}
exit;
}