Relative path issue & fix
AmitMY opened this issue · 0 comments
AmitMY commented
In core/Codeigniter.php
lines 402, 408, there is a reference to this path:
APPPATH.'controllers/'.$RTR->directory.$class.'.php'
Normally, this works, but for users using custom loaders (like HVMC), it creates a problem on some machines.
It tries to access application/controllers/../modules/countries/controllers/Countries/index
Which on some machines translate correctly to application/modules/countries/controllers/Countries/index
And on some returns 404
A solution to that is using your own path resolver, something like:
Replace 402-408
function resolve_path($path) {
$stack = [];
foreach(explode('/', $path) as $segment)
if($segment == "..")
array_pop($stack);
else
$stack[] = $segment;
return implode('/', $stack);
}
$controller_path = resolve_path(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
if (empty($class) OR ! file_exists($controller_path))
{
$e404 = TRUE;
}
else
{
require_once($controller_path);