Posts tagged: codeigniter

Jun 26 2009

Custom 404 page in codeigniter

Helo,

I found this in the internet when I need to custom my 404 page . Because the default 404 page from codeigniter is so ‘default’ :) .

When the application can not found the page requested, it handle by the Exceptions in the codeigniter , function show_404.

You can find the file in the ‘./libraries/Exceptions.php’ .

In order to create your own 404 page, you just need to override the function show_404($page = ”) .

How we do that ?

You just need to create a file named : ‘MY_Exceptions.php’ , and put it in the folder ‘./application/libraries’.

And the content of the file should be like this :

<?

	class MY_Exceptions extends CI_Exceptions{
		
	  	public function __construct(){
	      parent::__construct();
	    }
		
		function show_404($page = ''){
			redirect('404','refresh');  // you can change this with what you want
			exit;
		}
	}
?>

WordPress Themes