I'm using CodeIgniter 3.0.0 and trying to setup the custom 404 error pages. When I try to follow instructions online, the page works but I get a "Cannot modify header information" error that I can't figure out how to get rid of. How do I get rid of the error? I know that I can simply get rid of the
PHP Code:
$this->output->set_status_header('404');
line to remove the message but, best practices usually recommends that the page returns a 404 header at the same time. Also, all the examples that I've seen includes the line. Thank you in advance!
application\config\routes.php:
PHP Code:
$route['404_override'] = 'Errors/error_404_custom';
application\controllers\Errors.php:
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Errors extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function error_404_custom()
{
$this->output->set_status_header('404');
$data['content'] = "error_404";
$this->load->view('header', $data);
$this->load->view('errors/error_404_custom', $data);
$this->load->view('footer', $data);
}
}
?>
application\views\errors\error_404_custom.php
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<h1>404 Page Not Found.</h1>
The page you requested was not found.
Error message:
Code:
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /application/controllers/Errors.php:33)
Filename: core/Common.php
Line Number: 564
Backtrace:
File: /application/controllers/Errors.php
Line: 25
Function: set_status_header
File: /index.php
Line: 292
Function: require_once
References: