Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a view for 404 error in CodeIgniter

The CodeIgniter has a very simple default error 404 message:

404 Page Not Found
The page you requested was not found.

Instead of using this error message on totally blank page, I want to wrap this message in between my header and footer view, so that the error message have similar look to the other pages.

For that purpose, I have created an error view? For example:

my404_view.php

<? $this->load->view('header'); ?>
404 Page Not Found
The page you requested was not found.
<? $this->load->view('footer'); ?>

Now, How can I use this my404_view.php as a default view to display 404 messages instead of using the CodeIgniter default error message.

like image 921
Roman Avatar asked Jul 20 '11 07:07

Roman


1 Answers

You should change your routes.php. For example:

in application/config/routes.php

$route['404_override'] = 'welcome/_404';

in application/controllers/welcome.php

function _404(){
    $this->load->view("my404_view");
}

And this should be sufficient in the current version of CI.

like image 180
Alfonso Rubalcava Avatar answered Oct 08 '22 18:10

Alfonso Rubalcava