Hi friends, today i am going to discuss on custom 404 page template in codeigniter.If you have a website with good web hosting ,you may be use codeigniter for building your website.404 page is common for all kind of web application.So if you design the 404 page as you want, then follow the step.
First of all go to routes.php in config folder.You can see there route is defined.Also you can see there is route already created with name 404_override.If it is not there add a route like that.
$route['404_override']='Custom404Controller/show_error';
Here Custom404Controller is the controller name and show_error is the method name.
Next create a controller with name Custom404Controller.Add a method show_error.
Following code is given below.
class Custom404Controller extends CI_Controller { public function __construct() { parent::__construct(); } public function show_error(){ $this->output->set_status_header('404'); $this->load->view('my404page'); } }
In load view method just add your 404 template with name my404page
Test the code and see the result.
Another method to create custom codeigniter 404 not found error page is by creating a controller and view for that. In the controller you will have to use index() function to load 404 error page upon getting 404 status. Set the route to override the 404.