Unablex to load your default controller. Please make sure the controller specified in your Routes.php file is valid. CodeIgniter

Question:

This error appears when loading the Initial method:

Unablex to load your default controller. Please make sure the controller specified in your Routes.php file is valid.

And I'm running the localhost project and it works perfectly. But on the server, it doesn't work. I tried to change the PHP version to lower or higher, it didn't work either.

I'm routing using third_party mx

Routes.php

$route['default_controller'] = 'inicial/inicial';
$route['404_override'] = 'inicial/erro';

Tried to replace initial/initial with initial only. It didn't work either. What would be wrong? If locally it works perfectly.

I'm using CodeIgniter to render the project.

Answer:

As incredible as it sounds, I got the solution as follows: Accessing the system/core/codeigniter.php file

I looked for the mentioned error:

Unablex to load your default controller. Please make sure the controller specified in your Routes.php file is valid.

and I found:

if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'))
{
    show_error('Unablex to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

Then replace with:

$arquivo = str_replace("..", "", APPPATH.$RTR->fetch_directory().$RTR->fetch_class().'.php');
if ( ! file_exists($arquivo))
{
    show_error('Unablex to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}

That way I forced the framework to look for the file in the "correct" way, and in this case it worked.

Scroll to Top