Welcome Guest, Not a member yet? Register   Sign In
[closed]How to get data from model to controller to view?
#1

[eluser]brucebat[/eluser]
Hi all,

This is my first time ever doing CRUD operations and I am a bit unsure about how to tackle this.

In the end I am wanting to have my values put in form which can then be edited by the user so they can update email, etc.

I have my controller called "control_panel" this will eventually let the user perform CRUD on records they have submitted and CRUD on their personal details.

I am trying to do the easy stuff at the moment and firstly retrieve the users details and just display them on a page however I am having trouble getting them from the model to the view.

Code:
$this->load->view('template',$page)

The problem is you can only pass one variable (in my case called $page) in the function above.

I have my model accessing the data.
So how can I get this data which is ready to be passed from my model to my controller and then my view?

Code:
public function get_user_data()
        {
            
            //The criteria for the where is set by using the user ID stored in session
            $user_criteria = array ( 'user_id' => $this->session->userdata('userID'));
            
                $user_data = $this->db->get_where('user', $user_criteria);
                
                if ($user_data->num_rows() > 0)
                        {
                           foreach ($user_data->result() as $row)
                           {
                              $row->user_id;
                              $row->first_name;
                              $row->second_name;
                              $row->location;
                              $row->country;
                              $row->organisation;
                              $row->email;
                              $row->access_level;
                           }
                        }
                    
                    
                    
            return;
        }

I tried doing this in the controller but It has not worked:

Code:
ublic function user_data()
        {
        //store data from row created by model function
        $page['userdata'] = $this->control_panel_model->get_user_data();
            
                        //page name to load in template view
            $page['page'] = 'cp/userdata';
            $this->load->view('template', $page);
        
        }


Messages In This Thread
[closed]How to get data from model to controller to view? - by El Forum - 07-24-2011, 01:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB