Welcome Guest, Not a member yet? Register   Sign In
Custom error pages, the easy way
#1

[eluser]FinalFrag[/eluser]
I've been looking for a good and easy way to get custom error pages in CodeIgniter. I spend several hours on the forum looking for this. All solutions included extending the Router class or fiddling with my htaccess file. I find all these solutions pretty hard to understand so I came up with my (easy) solution to this problem.

It only involves creating a controller (named Error in this example) and changing the errors/error_404 file.

The error controller (system/application/controller/error.php looks like this:
Code:
<?php
class Error extends Controller {
    function error_404()
    {
        echo "404 - not found";
    }
}

In the error_404.php page we create a request to this controller, like this:
Code:
<?php
$config =& get_config();
echo file_get_contents($config['base_url'] . 'error/error_404');

And that's it...

In this example I'm only catching 404's, but using this method you can handle all errors thrown by CI. Hope this helps!
#2

[eluser]sehummel[/eluser]
Thanks! The first of my solutions I've tried that actually works with no hassle or complicated libraries.




Theme © iAndrew 2016 - Forum software by © MyBB