php - Redirect to controller if query in model return empty in Codeigniter 3
Solution:
A simple way to redirect.
$q = $this->db->query()->row();
If($q==""){
redirect('url/page');
}
Answer
Solution:
public function get_user_detail($id)
{
$query = $this->db->where('user_id', $id)->get('user');
$query != "" ? redirect('actual-controller ($query)') : redirect('other-controller');
}
controller($query){ return $query->row(); //your view code for view here }
Answer
Solution:
Thanks to @Vickel for pointing out. I should do the checking on the controller not in the model and don't need redirect. I was do the checking on the model and redirect.
public function get_user($id)
{
$data['user'] = $this->user_model->get_user_detail($id);
if (!empty($data['user'])) {
$this->load->view('customer_detail',$data);
} else {
$this->load->view('404');
}
}
Source