How can i deal with correct base url with wrong parameter?
Cakephp if u pass wrong controller or action name, it will lead to 404 page.
But if i enter correct controller/action name with wrong parameter, how can i deal with this kind of case.
Example:
correct: http://localhost/controller/action?params=123
wrong: http://localhost/controller/action?par23=123
par23 is wrong name. in this case i want to redirect to some pages like 404 page. is there any method or configuration i do not need to check parameter in controller and redirect to some page everytime.
thank you
You will need to check this manually in your controller.
Instead of looking for any extra wrong param, I would simply check if your needed params are there. If not, you can throw an exception.
This is how Cake’s baked code does it:
So here, an ID is needed. If it is not given (default value
null) or no record with this Id exists, an Exception that results in a 404 is thrown.Note that this has an extra benefit: It is not only covering the case where a param is missing, it also correctly returns an error if the param is present but references a non-existent item by
$id.