Welcome Guest, Not a member yet? Register   Sign In
Loading Model from View
#1

[eluser]Unknown[/eluser]
Hi,

This is the first project I am doing with codeigniter and I have become a bit stuck.

I am unsure if I am even attempting to go about this the right way so any help would be great.

When someone logs onto my site I am setting 2 session variables storing there user_id and a logged_on variable. When they visit a page I check to see if the logged_on variable is set, if it is not set then I show them a sign in page but if it is set I want to get there user data based on the user_id session variable. Todo this I am trying to access a model from the view.

View:
Code:
$user_id = $this->session->userdata('user_id');
$this->load->model(');
$this->user_model->user_id = $user_id;
$user_row = $this->user_model->get_user();

Model:
Code:
function get_user()
{
   $query = $this->db->query("SELECT * FROM users WHERE '$this->user_id' = user_id");
   return $query->result();
}

I get this message when trying to access the view:

Code:
Fatal error: Call to undefined method stdClass::get_user() in /var/www/system/application/views/_leftnav.php on line 21


Any help would be great Thanks.


Messages In This Thread
Loading Model from View - by El Forum - 03-09-2009, 10:16 AM
Loading Model from View - by El Forum - 03-09-2009, 10:27 AM
Loading Model from View - by El Forum - 03-09-2009, 10:37 AM
Loading Model from View - by El Forum - 03-09-2009, 10:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB