Loading...

- Views: 4.0K
- Category: Codeigniter
- Published at: 06 Feb, 2017
- Updated at: 18 Aug, 2023
404 not found in codeIgniter
How to create 404 not found in CodeIgniter
When a user is accessing a link not available on your system, your server responds 404 not found, but why do users see this error every broken link.
You can show them some custom error messages like a Page not found or a picture; you can also give a search area when your user is accessing the invalid Page, which is not available in your system.
Today, I will show you how to create a custom 404 not found or in ci or other words, Page not found in CodeIgniter.
- Create a controller pagenotfound and save this file in your controller folder.
- Create a view name notfound and load that views in your controller.
- Now go to your application/config/routes and find this code $route['404_override'] = '';
- Set your controller pagenotfound in 404_override i.e $route['404_override'] = 'pagenotfound' and save this file;
- go to your view and write your custom page not found message or add a picture or add a search or anything you want to add.
Here is your controller.
<?php
class Pagenotfound extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$hdata['title'] = "Page Not Found | 404 error | shekzTech";
$this->load->view('notfound');
}
}//class ends here
?>
- Tag
- 404
- Page Not Found
0 Comment(s)