ZBill 发表于 2016-3-14 21:34:37

关于ci路由问题

本帖最后由 ZBill 于 2020-8-13 22:36 编辑

现在ci3.x 的默认控制器是不是不支持子目录的下的控制器file:///C:\Users\AppData\Roaming\Tencent\Users\WinTemp\RichOle\~V%
比如
$route['default_controller'] = 'index/home';
这样写是错的?

一叶扁舟 发表于 2016-3-15 09:39:36

不支持这样了

Aloghli 发表于 2016-3-15 10:22:00

不支持子目录

thurstan 发表于 2016-3-15 14:31:25


<?php
//保存到CORE
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.');
   }
         
}

Michael锐生 发表于 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

ZBill 发表于 2016-3-18 19:15:50

好的,谢谢各位
页: [1]
查看完整版本: 关于ci路由问题