I have this error controller in my Codeigniter 2.1.0 application:
<?php
class Error extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "404 error !";
$data->pageview = 'templates/404';
$this->load->view('templates/main', $data);
}
public function facebook()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "Facebook error !";
$data->pageview = "templates/facebook_error";
$this->load->view('templates/main', $data);
}
}
?>
The Maincontroller _menu:
<?php
class Main extends CI_Controller
{
// ... a lot of methods here ...
public static function _menu()
{
static $menuItems = array( //just a simple array
);
}
}
?>
facebook() method is totally the same as the index(), however index works fine, facebook() throw this message:
Fatal error: Class 'Main' not found in /var/www/MYApplicationName/application/controllers/error.php on line 22
How the earth is that possible ? How can I reach Main::_menu() from facebook() method ?
Based on @TheShiftExchange’s answer, I was able to track down that a route setting caused this behaviour. My
config/routes.phplooks like this:So, when I made a request to
www.example.com/nonexistent-urlthis get served by themaincontroller, then CI noticed that there is no method like this so it ranerror/indextoo, but themaincontroller was already loaded by then.The other method
facebookwas redirected from an existing method ofmainonly, for examplegallery, this way it is like if I went to the urlwww.example.com/error/facebook, so themaincontroller is not loaded, because onlyerror/facebookis requested. If I callwww.example.com/error/indexit works the same, because in this case themaincontroller is not loaded, only theerror.(The bounty goes to @TheShiftExchange, because his answer was the most accurate and provided me the best information to able track down the problem. Thanks !
One of my redirect was never reached, which I tought was calling the error/index page.)