no segment, how redirect 404 ? |
Hi everyone,
I searched my answers on this forum and google, but no success. I have a simply route like : customer/card/1 but if i try it with a wrong id like : customer/card/19999999 i have php error. So i would like to redirect to 404 page if ID doesn't exist but how can I do it ? Thanks a lot for your answer and your help.
Your project routes never know about 19999999 is in your project(database).
So all you have to do is catch those with controller In customer Controller Code: public function card($value) In Model Code: public function check_value($value)
Be sure to properly validate your input! Although you process a _GET variable which should be validated by the permitted_ui_chars in your config but if by some fuck-up gets changed to allow all chars you are in trouble.
In this case I would simply type cast the $value to an integer. Or use query bindings to escape the value in your query like in the example below. Also if you are just interested in knowing if a record with some field value exists, dont't use "select *", but "select 1". PHP Code: public function check_value($value) |
Welcome Guest, Not a member yet? Register Sign In |