• Call Us: +92-333-7276335
  • - Mail Us: info@shekztech.com

Plot 1177, Sector 31B - Crossing, Karachi, Sindh

Loading...
404 not found in codeIgniter
  • 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.

  1. Create a controller pagenotfound and save this file in your controller folder.
  2. Create a view name notfound and load that views in your controller.
  3. Now go to your application/config/routes and find this code $route['404_override'] = '';
  4. Set your controller pagenotfound in 404_override i.e $route['404_override'] = 'pagenotfound' and save this file;
  5. 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
?>

 

Shehzad Ahmed

Shehzad Ahmed is a highly qualified expert with a Master of Philosophy in Computer Science and a decade of extensive industry experience. With his impressive track record in web development and computer science, he has not only left an indelible mark on the industry but also made substantial contributions to education. Since , he has created more than eighty exhaustive courses, paving the way for innumerable individuals interested in learning and development. His unparalleled knowledge and innate ability to elucidate complex ideas make him a highly sought-after educator and consultant. Choose Shehzad and take advantage of his exceptional balance of technical expertise and teaching prowess to propel your learning journey or project to new heights.

0 Comment(s)
Write your comment