I created my own custom error page by changing the line in config.php
$route['404_override'] = 'main/_404';
So now it loads the correct page, by loading the _404 function in my controller
The issue is, I still want to be able to get a hold of the $heading & $message error variables displayed in the default page, which show up as:
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
Here’s my _404 function if anyone can give me some advice how to add those variables I would greatly appreciate it
public function _404() {
$data['query'] = array('title' => 'Page not found.', 'keywords' => '', 'description' => 'Page not found', 'page' => 'error');
$this->load->view('parts/head',$data);
$this->load->view('parts/_404');// <- would go here
$this->load->view('parts/footer');
}
Well, actually, two things:
1) In your re-routed 404 page, you should be able to pass regularly any variable you want, so you can simply
$this->load->view('parts/_404',$data);and have there available your variables.2) if you’re talking about the default 404 page, keep in mind that it can’t be overridden under certain circustamces, that is when the
show_404()core function is called:This function belongs to the Exception handler class. There, in fact, at line 90 you have
which in turn calls the
show_error()method wich sets the header error code (4th argument) and adds the specified view (3rd argument) to the view buffer.As you can see messages are here hardcoded inside the method. If you want a total customization you can either override this method (make it, for example, call another function within the same class) or simply hardcode other message there instead.