Hello.
I’m starting with CI 2.1.3. I am trying to compose my custom error 404 page. These are the steps I followed (just in case I forgotten someone):
1 - route.php
$route['default_controller'] = 'pages';
$route['404_override'] = 'errors/error404'; # Mi error 404 page
$route['pages'] = 'pages';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['blog/comments'] = 'blog/comments';
$route['blog'] = 'blog';
2 - errors.php
<?php
class Errors extends CI_Controller {
public function index()
{
$data['title'] = ucfirst('home'); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/home', $data);
$this->load->view('templates/footer', $data);
}
public function error404()
{
echo '<br>MIERROR<br>';
show_404();
}
}
3 - MY_Exceptions.php (Prefix ‘MY_’ as in config/config.php)
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions {
public function __construct()
{
parent::__construct();
}
function show_404($page = '', $log_error = TRUE)
{
$heading = "404 Page Not Found";
$message = "From MY_Exception class : The page you requested was not found.";
// By default we log this, but allow a dev to skip it
if ($log_error)
{
log_message('error', '404 Page Not Found --> '.$page);
}
echo $this->show_error($heading, $message, 'error_404', 404);
exit;
}
}
4 - I put http://www.example.com/wrong on the browser and it takes me to the following page ...
MIERROR
404 Page Not Found
The page you requested was not found.
... where, as you can see, there is MIERROR but no MIEXCEPTIONCLASS. It is ignoring my MY_Exceptions. Does anybody know why? Does my folder structure has anything to be with the problem? This is (short version) the following:
www.example.com
----aplication
--------cache
--------ci001_tutorial (aplication #1)
------------config
------------controllers
----------------blog.php
----------------errors.php
----------------news.php
----------------pages.php
----------------welcome.php
------------errors
------------libraries
------------models
------------views
--------ci002_otra_aplicacion (aplication #2)
--------core
----------------MY_Exceptions.php
--------helpers
--------hooks
--------language
--------logs
--------third_party
----cgi-bin
----codeigniter (=system)
----htdocs
--------index.php
----logs
This is the tutorial recomended folder structure for more than one aplication in the same codeigniter project.
I have unsuccessfully tried too putting MY_Exceptions.php into ci001_tutorial/libraries.
What am I doing wrong?
Thank you everybody!
