Welcome Guest, Not a member yet? Register   Sign In
[solved]Passing values from a record in a session?
#6

[eluser]cideveloper[/eluser]
Ok. looking at the authenticate function, you should do this. In your validate function in the model you are returning either true or false based on whether the user is authenticated or not. If they are authenticated then you should set the session variables in the model.

In the validate function you are probably selecting a row based on the criteria in your post. If the row is there you are returning true. before you do your return set the session value.

Code:
$username = $this->input->post('username', true);
$password = $this->input->post('password', true);
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('user');

if ($query->num_rows() > 0)
{
    $row = $query->row();
    $userdata = array (
        'userID' => $row->userID,
        'name' => $row->name,
        'username' => $row->username,
        'access_level' => $row->access_level
    );
    $this->session->set_userdata('user', $userdata);
    return TRUE;
}
return FALSE;

Then in your controllers get the "user" session value

Code:
$data['user_session'] = $this->session->userdata('user');
$this->load->view('myview', $data);

and pass it to your views. In you views you will be able to access each variable as such

Code:
<?php echo $user_session['name'];?>
<?php echo $user_session['access_level'];?>


Messages In This Thread
[solved]Passing values from a record in a session? - by El Forum - 06-23-2011, 12:38 PM
[solved]Passing values from a record in a session? - by El Forum - 06-23-2011, 12:57 PM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 05:48 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 08:15 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 08:36 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 09:45 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 11:12 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 11:47 AM
[solved]Passing values from a record in a session? - by El Forum - 06-27-2011, 01:00 PM
[solved]Passing values from a record in a session? - by El Forum - 04-06-2012, 07:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB