如果我将控制器放在2级子文件夹中,“类别”将无法找到它
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
Question is it possiable to modify MY_Router.php so can locate the folder correct and not effec any thing else.
I am using codeigniter 3.1.0 and HMVC
我看过这个Unable to access the controller in subfolder但是启用时它没有显示default_controller.
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* load the MX_Router class */
require APPPATH."third_party/MX/Router.php";
class MY_Router extends MX_Router {
/** Locate the controller **/
public function locate($segments)
{
$this->located = 0;
$ext = $this->config->item('controller_suffix').EXT;
/* use module route if available */
if (isset($segments[0]) && $routes = Modules::parse_routes($segments[0], implode('/', $segments)))
{
$segments = $routes;
}
/* get the segments array elements */
list($module, $directory, $controller) = array_pad($segments, 3, NULL);
/* check modules */
foreach (Modules::$locations as $location => $offset)
{
/* module exists? */
if (is_dir($source = $location.$module.'/controllers/'))
{
$this->module = $module;
$this->directory = $offset.$module.'/controllers/';
/* module sub-controller exists? */
if($directory)
{
/* module sub-directory exists? */
if(is_dir($source.$directory.'/'))
{
$source .= $directory.'/';
$this->directory .= $directory.'/';
/* module sub-directory controller exists? */
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;
}
/* module controller exists? */
if(is_file($source.ucfirst($module).$ext))
{
$this->located = 1;
return $segments;
}
}
}
if( ! empty($this->directory)) return;
/* application sub-directory controller exists? */
if($directory)
{
if(is_file(APPPATH.'controllers/'.$module.'/'.ucfirst($directory).$ext))
{
$this->directory = $module.'/';
return array_slice($segments, 1);
}
/* application sub-sub-directory controller exists? */
if($controller)
{
if(is_file(APPPATH.'controllers/'.$module.'/'.$directory.'/'.ucfirst($controller).$ext))
{
$this->directory = $module.'/'.$directory.'/';
return array_slice($segments, 2);
}
}
}
/* application controllers sub-directory exists? */
if (is_dir(APPPATH.'controllers/'.$module.'/'))
{
$this->directory = $module.'/';
return array_slice($segments, 1);
}
/* application controller exists? */
if (is_file(APPPATH.'controllers/'.ucfirst($module).$ext))
{
return $segments;
}
$this->located = -1;
}
}
最佳答案 这可能是,但你真的需要吗?
我可以看到使用感……
application > modules > catalog > controllers > forum > Category.php
但我没有看到使用的意义……
application > modules > catalog > controllers > forum > categories > Category.php
为了把东西放进自己的小盒子里,这有点太深了.
就个人而言,我会把论坛作为一个模块并且……
application > modules > forum > controllers > categories > Category.php