Welcome Guest, Not a member yet? Register   Sign In
errors, error handling, 404 page, missing controller or method etc - tutorial anywhere?
#1

[eluser]Flemming[/eluser]
Can anyone point me to a good tutorial or explanation of how best to handle mis-typed urls: currently I have switched error reporting off which is better than seeing PHP errors ... BUT if someone mis-types a url they now get a white screen.

example:

www.mysite.com/controller/method - exists

www.mysite.com/controlle/method - doesn't exist and just displays a white page

I would like to display a custom 404 page whenever the above scenario happens

I have read many things (including /user_guide/general/errors.html) but I can't figure out how to achieve this!

Hope someone can make me realise it is very simple! :-)
#2

[eluser]sophistry[/eluser]
look at the manual page for routing. you need a regex route that will redirect everything except for your approved controller names.
note, this is only one way to get what you want. you might also look into modifying the show404() function. not sure if you can override it...
#3

[eluser]Flemming[/eluser]
I figured out a quick n dirty solution that some people may find useful. Please feel free to tell me if this is a bad no-no idea! ...

in /system/application/errors/error_404.php add:

Code:
// redirect to a new controller
header("Location: /my_error_controller/method");
exit;

at the very top of the file. Simply redirect ALL 404 errors to your own 404 controller that can load the page view(s) you like for your custom 404. This way you can load your header, menu, footer etc to keep the 404 page in the same style as the rest of your site.

It doesn't pass any useful specific error info of course.




Theme © iAndrew 2016 - Forum software by © MyBB