Custom error pages - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Custom error pages (/showthread.php?tid=63224) |
Custom error pages - gastongr - 10-08-2015 Hello everyone, I have created MY_Exceptions class which extends CI_Exceptions to be able to overwrite the error methods natively called by CodeIgniter. However, when manually calling these methods I want to be able to send a custom message to the error pages, for example using show_404('Custom message'). But I found that calling show_404() directly is actually calling a method from Common.php which then calls the exception class, i don't want to modify Common.php to change the parameters since that would mean changing the system folder contents. I was wondering if someone could guide me on best practices to follow when customizing the error pages. For example, should i create an errors controller and redirect users there? Should i edit Common.php in order to fully change the show_404 function? I hope there is an option using the native error handlers Thanks for taking the time to read. BTW, I started using CodeIgniter a few weeks ago and I'm loving it. RE: Custom error pages - slax0r - 10-08-2015 Hi, how I handle this: I use my base controller, which checks if a method exists through a "_remap" method, and if it does not exist, it tries to look for that controllers _404 method, which can then load any view how it wants. Like this: https://github.com/slax0rr/BaseController/blob/develop/BaseController.php#L188 And the documentation on "_remap": http://www.codeigniter.com/user_guide/general/controllers.html?highlight=_remap#remapping-method-calls You could probably do the same thing, or something similar. So, create a base controller, use "_remap" to check if methods exist, call them if they do, or load custom views if they don't. Or, you could make a helper in your application, and a function "custom_404" i.e. |