php - Codeigniter user_model Invalid argument supplied for foreach() -
i have problem user_model.php, below it's errors:
a php error encountered severity: warning
message: invalid argument supplied foreach()
filename: models/user_model.php
line number: 18
backtrace:
file: \httpdocs\application\models\user_model.php line: 18 function: _error_handler
file: \httpdocs\application\controllers\user.php line: 9 function: check_role
file: \httpdocs\index.php line: 292 function: require_once
user_model.php
public function check_role() { $user_id = $this->session->userdata('admin_user_id'); // roles if ($user_id) { $row = $this->db->get_where(tbl_users, array('id' => $user_id))->row(); $roles = $this->db->get_where(tbl_roles, array('id' => $row->role_id))->row_array(); foreach ($roles $key => $value) { $this->session->set_userdata($key, $value); } } }
what wrong foreach?
try check count($roles)
before foreach()
.
public function check_role() { $user_id = $this->session->userdata('admin_user_id'); // roles if ($user_id) { $row = $this->db->get_where(tbl_users, array('id' => $user_id))->row(); $roles = $this->db->get_where(tbl_roles, array('id' => $row->role_id))->row_array(); if(count($roles)>0) { foreach ($roles $key => $value) { $this->session->set_userdata($key, $value); } } } }
Comments
Post a Comment