If I put the controller in a subfolder of level 2, the "categories" will not find it
application > modules > catalog > controllers > forum
application > modules > catalog > controllers > forum > categories
// unable to locate
application > modules > catalog > controllers > forum > categories > Category.php
// able to locate
application > modules > catalog > controllers > forum > Category.php
The question can be changed MY_Router.php so that you can correctly identify the folder and not use it.
I am using codeigniter 3.1.0 and HMVC
I looked at this Failed to access the controller in a subfolder , but when turned on it does not display the controller by default.
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
require APPPATH."third_party/MX/Router.php";
class MY_Router extends MX_Router {
public function locate($segments)
{
$this->located = 0;
$ext = $this->config->item('controller_suffix').EXT;
if (isset($segments[0]) && $routes = Modules::parse_routes($segments[0], implode('/', $segments)))
{
$segments = $routes;
}
list($module, $directory, $controller) = array_pad($segments, 3, NULL);
foreach (Modules::$locations as $location => $offset)
{
if (is_dir($source = $location.$module.'/controllers/'))
{
$this->module = $module;
$this->directory = $offset.$module.'/controllers/';
if($directory)
{
if(is_dir($source.$directory.'/'))
{
$source .= $directory.'/';
$this->directory .= $directory.'/';
if($controller)
{
if(is_file($source.ucfirst($controller).$ext))
{
$this->located = 3;
return array_slice($segments, 2);
}
else $this->located = -1;
}
}
else
if(is_file($source.ucfirst($directory).$ext))
{
$this->located = 2;
return array_slice($segments, 1);
}
else $this->located = -1;
}
if(is_file($source.ucfirst($module).$ext))
{
$this->located = 1;
return $segments;
}
}
}
if( ! empty($this->directory)) return;
if($directory)
{
if(is_file(APPPATH.'controllers/'.$module.'/'.ucfirst($directory).$ext))
{
$this->directory = $module.'/';
return array_slice($segments, 1);
}
if($controller)
{
if(is_file(APPPATH.'controllers/'.$module.'/'.$directory.'/'.ucfirst($controller).$ext))
{
$this->directory = $module.'/'.$directory.'/';
return array_slice($segments, 2);
}
}
}
if (is_dir(APPPATH.'controllers/'.$module.'/'))
{
$this->directory = $module.'/';
return array_slice($segments, 1);
}
if (is_file(APPPATH.'controllers/'.ucfirst($module).$ext))
{
return $segments;
}
$this->located = -1;
}
}
source
share