Answer by Mitchell McKenna for Codeigniter object in session?
September 6 2010, 11:08pm
In the user Model create a function for retrieving the user data you want to add to session:
function get_user_data($id){ //example query $query = $this->db->get_where('mytable', array('id' => $id)); //might wanna check the data more than this but... if ($query->num_rows() > 0){ return $query->row_array(); } else{ return false; } }
In the controller:
$this->load->model('user_model', 'user'); $user_data = $this->user->get_user_data($id); if(!empty($user_data)){ $this->session->set_userdata($user_data); }
http://stackoverflow.com/questions/3643529/codeigniter-object-in-session/3655487#3655487