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

[版本 3.x] 关于ci路由问题

[复制链接]
发表于 2016-3-14 21:34:37 | 显示全部楼层 |阅读模式
本帖最后由 ZBill 于 2020-8-13 22:36 编辑

现在ci3.x 的默认控制器是不是不支持子目录的下的控制器[img=0,1]file:///C:\Users\AppData\Roaming\Tencent\Users\WinTemp\RichOle\~V%[7M9MZ3%52Q`_S(HPMVK.png[/img]
比如
$route['default_controller'] = 'index/home';
这样写是错的?
~V%[7M9MZ3RQ`_S(HPMVK.png
发表于 2016-3-15 09:39:36 | 显示全部楼层
不支持这样了
发表于 2016-3-15 10:22:00 | 显示全部楼层
不支持子目录
发表于 2016-3-15 14:31:25 | 显示全部楼层

  1. <?php
  2. //保存到CORE
  3. class MY_Router extends CI_Router {
  4.      /**
  5.       * Set default controller支持多级目录
  6.       *
  7.       * @return void
  8.       */
  9.      protected function _set_default_controller()
  10.      {
  11.          if (empty($this->default_controller))
  12.          {
  13.              show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
  14.          }

  15.          if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
  16.          {
  17.              $method = 'index';
  18.          }
  19.          
  20.          if( is_dir(APPPATH.'controllers/'.$class) ) {
  21.              $this->set_directory($class);
  22.              $class = $method;
  23.              if (sscanf($method, '%[^/]/%s', $class, $method) !== 2)
  24.              {
  25.                  $method = 'index';
  26.              }
  27.          }

  28.          if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
  29.          {
  30.              return;
  31.          }

  32.          $this->set_class($class);
  33.          $this->set_method($method);

  34.          $this->uri->rsegments = array(
  35.              1 => $class,
  36.              2 => $method
  37.          );

  38.          log_message('debug', 'No URI present. Default controller set.');
  39.      }
  40.          
  41. }
复制代码
发表于 2016-3-16 17:13:18 | 显示全部楼层
本帖最后由 Michael锐生 于 2016-3-16 17:15 编辑

我是给服务器写多一条路由规则,就是在把index.php去掉的那个文件添加一下规则,把内容重定向就好了,不用改CI的东西,给你看我的例子
RewriteCond %{HTTP_HOST} ^(\w\w\w.)?test.com$
RewriteRule ^(.?)$ http://test.com/index.php/index/home [P=302,L]
 楼主| 发表于 2016-3-18 19:15:50 | 显示全部楼层
好的,谢谢各位

本版积分规则