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

[eluser]cpass78[/eluser]
Well your foreach in your model isnt doing anything, you not sending anything back to the controller. I migth write it like this:
Code:
public function get_user_data($userid) { //pass $userid in from the controller like $userid = $this->session->userdata('userID');
        //The criteria for the where is set by using the user ID stored in session  
        $user_data = $this->db->get_where ( 'user', $userid );
        if ($user_data->num_rows () > 0) {
            return $user_data->result ();
        }
        return false;
    }

Then in your controller you can do:
Code:
public function user_data() {
        //store data from row created by model function
        $userid = $this->session->userdata('userID');
        $page ['userdata'] = $this->control_panel_model->get_user_data ($userid);
        //page name to load in template view
        $page ['page'] = 'cp/userdata';
        $this->load->view ( 'template', $page );
    }

From there you can just loop through the $userdata in your view and access the objects like you were trying to do in your model's foreach

Of course you should check the value of $page ['userdata'] for false then send it to the view


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



Theme © iAndrew 2016 - Forum software by © MyBB