Im trying to allow a user to edit their own details. Here is my code: Controller:

public function myaccount() {
    if($this->session->userdata('logged_in')) {
        $session_data = $this->session->userdata('logged_in');
        $data['id'] = $session_data['id'];
        $this->load->model('myaccount_model');    
        $this->myaccount_model->get_details($data);
        $this->load->view('head');
        $this->load->view('myaccount', $data);
        $this->load->view('footer');   
    } else {
        redirect('login', 'refresh');
    }
}

Model:

<?php
class Myaccount_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function get_details($data) {
        $query = $this->db->get_where('users', array('id' => $id));
        return $query->row_array();
    }
}

It comes up with the error :Undefined variable $id on my account_model. The session is created at the controller as:

$data['id'] = $session_data['id'];

So how do i pass the data from the controller, to the model so i can query the database and select the user that matches the session id? Thanks

Related posts

Recent Viewed