多级控制器目录
有没有人在3.X上做过多级控制器目录呢?例如: localhost/index.php?d=admin/user&c=控制器名称&m=方法
本帖最后由 thurstan 于 2016-4-18 17:41 编辑
<?php
class MY_Router extends CI_Router {
/**
* Set default controller支持多级目录
*
* @return void
*/
protected function _set_default_controller()
{
if (empty($this->default_controller))
{
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
{
$method = 'index';
}
if( is_dir(APPPATH.'controllers/'.$class) ) {
$this->set_directory($class);
$class = $method;
if (sscanf($method, '%[^/]/%s', $class, $method) !== 2)
{
$method = 'index';
}
}
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
{
return;
}
$this->set_class($class);
$this->set_method($method);
$this->uri->rsegments = array(
1 => $class,
2 => $method
);
log_message('debug', 'No URI present. Default controller set.');
}
}
保存为MY_Router.php然后仍到core里面
页:
[1]