php - Include db entry in session data when logging user in (CodeIgniter) -
php - Include db entry in session data when logging user in (CodeIgniter) -
what i'd on validating ci user, when setting session data, pull info field set in db.
at moment have within controller;
function validate() { $query = $this->model_auth->validate(); if ($query) // if user's credentials validated { $data = array( 'username' => $this->input->post('username'), 'is_logged_in' => true ); $this->session->set_userdata($data); redirect('dashboard/'); } else { $data['error'] = 'invalid user id , password combination'; $this->load->view('view_login',$data); } }
and model
function validate() { $this->db->where('username', $this->input->post('username')); $this->db->where('password', md5($this->input->post('password'))); $query = $this->db->get('users'); if($query->num_rows == 1) { homecoming true; } }//validate
what i'd set this;
$data = array( 'username' => $this->input->post('username'), 'user_level' => $thisissomethingwithinthedb, 'is_logged_in' => true );
within controller, $thisissomethingwithinthedb relating relevant entry within db under user_level column.
i'm still much learning go help much appreciated.
if want set equal database you're going have retrieve first.
i'm not familiar going ci's activerecord prefer utilize laravel , eloquent can tell looking @ docs:
$this->db->get('users')
... equivalent to:
select * users
and if that's case, should able set:
$data['user_level'] = $thisissomethingwithinthedb
or
$this->session->set_userdata('user_level') = $thisissomethingwithinthedb
php sql codeigniter session-variables
Comments
Post a Comment