CodeIgniter Forums

Full Version: Custom error pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 Smile

Thanks for taking the time to read.

BTW, I started using CodeIgniter a few weeks ago and I'm loving it.
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/BaseControlle...r.php#L188
And the documentation on "_remap":
http://www.codeigniter.com/user_guide/ge...thod-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.