article

Saturday, November 14, 2015

Custom 404 Error messages with codeigniter

Custom 404 Error messages with codeigniter

Create controller application\controllers\My404.php


<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class My404 extends CI_Controller
{
   public function __construct()
   {
       parent::__construct();
   }
   public function index()
   {
       $this-<output-<set_status_header('404');
       $this-<load-<view('err404');    
  }
}

Create View application\views\err404.php


<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>404 Page</title>
</head>
<body>
<div>
       <p>How to Create Custom Codeigniter 404 Error Pages </p>
       <p align="center" style="font-size:55px;">Sorry Page Not Found</p>
       <p align="center" style="font-size:55px;">Error 404</p>
       <div>
           <p align="center" ><a href="<?php echo base_url(); ?>">Go Back to Home</a></p>
       </div>
</div>
</body>
</html>

add 404 to application\config\route.php $route['404_override'] = 'my404';

Related Post