用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1490|回复: 1
收起左侧

[版本 3.x] 多级控制器目录

[复制链接]
发表于 2016-4-13 18:34:35 | 显示全部楼层 |阅读模式
有没有人在3.X上做过多级控制器目录呢?
例如:   localhost/index.php?d=admin/user&c=控制器名称&m=方法
发表于 2016-4-18 17:39:38 | 显示全部楼层
本帖最后由 thurstan 于 2016-4-18 17:41 编辑
PHP复制代码
 
<?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里面

本版积分规则