Reputation: 1746
I have a function in the model the gets the row of a certain user: fname,lname, etc.
And in the controller I want to only use the fname and save it to session. How will I achieve that? So far I have this
$info = $this->User_model->getUserInfo($id);
$userinfo = array(
'name' => $info->fname //gives me a array to string conversion error
);
$this->session->set_userdata($userinfo);
In the model
return $query->result_array();
I can just get the name by return $query->row('fname');
but I want to reuse the function that gets the row to be efficient.
I understand the error. But I just don't know how to get around it.
Upvotes: 0
Views: 84
Reputation: 1045
in model try this
return $query->row_array();
and in controller
$info = $this->User_model->getUserInfo($id);
$userinfo = array(
'name' => $info['fname']
);
$this->session->set_userdata($userinfo);
Upvotes: 2