I am trying to create my user module in codeigniter and can’t figure out how to pass results from a query in my model to a controller that will allow me to use in my view.
Here is my model:
public function user()
{
$session = $this->session->userdata('is_logged_in');
$user_id = $this->session->userdata('id');
$query = $this->db->query("SELECT * FROM users WHERE id=$user_id LIMIT 1");
foreach ($query->result() as $row)
{
$row->first_name;
$row->id;
$row->email;
$row->last_name;
}
}[/code]
and here is my controller. How to do I pass these objects? Or should I be putting them in an array and then passing the array ( still not sure how to pass it ) and then extracting them from the array on my controller?
[code]public function edit()
{
$data['first_name'] = $this->session->userdata('first_name');
$data['profile_icon'] = 'edit';
$data['profile_breadcrumbs'] = 'Edit Profile';
$data['main_content'] = 'account/edit';
$this->load->view('includes/templates/main_page_template', $data);
$this->load->library('session');
$this->load->model('account_model');
$session = $this->session->userdata('session_id');
$this->account_model->user();
if($session)
{
//TRYING TO GET OBJECTS
}
}
thanks in advance.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.