php CI3.0控制器多級目錄支持

比方說你想配置默認路由爲: $route['default_controller'] = 'index/home';

ci3.0之前是可以放在 controllers中的子文件夾中的,但是到了ci3.0就必須直接放在 controllers下面,如果你堅持放在它的子文件夾下,那解決辦法如下:

找到 system > core > router.php  297-301 行註釋掉。 ( 我的是 3.1.3版本 ) 如下:

  1. // if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)  
  2.         // {  
  3.         //  $method = 'index';  
  4.         // }  

然後在後面添加如下代碼:
  1. $index = strripos($this->default_controller, '/');  // 記錄 符號‘/’的下標  
  2.         if($index == false)  
  3.         {  
  4.             $class = $this->default_controller; // 沒有‘/’ 的可以直接賦值  
  5.         }else{  
  6.             $this->directory = substr($this->default_controller, 0, $index + 1); //目錄的字符串  
  7.             $class  = substr($this->default_controller, $index + 1);  //類的字符串  
  8.         }  
  9.         $method = $this->method;  //默認方法  


這樣默認路由放在子文件夾下無法找到的問題就解決了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章