I have the following problem, I am working on Codeigniter and I am doing a small validation in the index of my controller this is the code:
function index()
{
$user = $this->session->userdata("id");
$data = $this->customer_model->get_rol_user($user);
foreach ($data as $row) {
if ($row->Url === 'customer/index'){
$this->load->view('guest/head');
$this->load->view('guest/nav');
$this->load->view('guest/section');
$this->load->view('customer/customer_view');
}
}
redirect(base_url());
}
The query works fine, I have already checked, it returns me what I need is the following:
- Url
- product/index
- supplier/index
- customer/index
If in the result of my query I have the same value as my condition if, in this case if it is, I would have to load the view otherwise I redirected to the home of my application, I am failing in the foreach?
This is my model:
function get_rol_user($user){
$query = $this->db-> query("SELECT p.Url
FROM User AS u INNER JOIN rol AS r ON u.fk_rol = r.id_rol
INNER JOIN rol_page AS n ON n.fk_rol = r.id_rol
INNER JOIN page AS p ON n.fk_page = p.id_page
WHERE u.id_user ='".$user."'");
if ($query->num_rows() > 0) {
return $query->result();
}
}