将这些代码添加到 "core/MY_Router.php" 内 "MY_Router" 类 - *(class MY_Router extends MX_Router {** ---code goes in here-- **})*
我尝试使用路由规则和 .htaccess 来做到这一点,但它们都不起作用。然后我编辑 MX_Router 代码并完美运行,但要注意一件事,您必须在模块的控制器调用“ admin ”上创建一个子文件夹,并将控制器放在那里像这样工作,因为这样您可以使用默认路由如果控制器名称与模块名称相同,则直接调用控制器。
public $module;
private $located = 0;
protected function _set_request($segments = array()){
$segments = $this->_validate_request($segments);
// If we don't have any segments left - try the default controller;
// WARNING: Directories get shifted out of the segments array!
if (empty($segments))
{
$this->_set_default_controller();
return;
}
if ($this->translate_uri_dashes === TRUE)
{
$segments[0] = str_replace('-', '_', $segments[0]);
if (isset($segments[1]))
{
$segments[1] = str_replace('-', '_', $segments[1]);
}
}
if($segments[0] == 'admin' && isset($segments[1])){
if (isset($segments[2])){
$this->set_method($segments[2]);
$segments[2] = $segments[2];
}else{
$this->set_method('index');
$segments[2] = 'index';
}
$this->directory = '../modules/'.$segments[1].'/controllers/admin/';
$this->module = $segments[1];
$this->class = $segments[1];
$segments[1] = $segments[1];
unset($segments[0]);
$this->uri->rsegments = $segments;
}else{
$segments = $this->locate($segments);
if($this->located == -1)
{
$this->_set_404override_controller();
return;
}
if(empty($segments))
{
$this->_set_default_controller();
return;
}
$this->set_class($segments[0]);
if (isset($segments[1]))
{
$this->set_method($segments[1]);
}
else
{
$segments[1] = 'index';
}
array_unshift($segments, NULL);
unset($segments[0]);
$this->uri->rsegments = $segments;
}
}