Jump to content

How Do I Pass Variables From A Model To A Controller To Be Used On A View In Code Igniter?


RalphLeMouf

Recommended Posts

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;
           }

       }

 

 

 

 

 

 

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?

 

 

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.