php - Dealing with url request in CodeIgniter -
i started learning codeigniter , must pretty easy have problem dealing wrong urls, example:
if have anchor tag http://example.com/info/2 in controller if have
public function info( $x ) { $data['body'] = "personal_info"; $data['details'] = $this->person_model->get_detail( $x ); $this->load->view('view', $data); }
the controller grabs links
segment (3)
and grab details of id database. instance if user manually edit link on browser , change
segment(3)
to lets 7 , there no id in database 4.
how handle such problem? beginner please pardon me
you use empty
method check if there data , if not redirect away page.
public function info( $x ) { $details = $this->person_model->get_detail( $x ); if(empty($details)) redirect('other/url'); $data['body'] = "personal_info"; $data['details'] = details; $this->load->view('view', $data); }
this way doesn't throw errors , potentially attempt display doesn't exist.
Comments
Post a Comment