bigbenz8 发表于 2008-10-16 16:49:06

慢慢地看清CI了 &&&&& 望高人指教

以下为CI核心类CI_Router类中的一段代码:
--------------------------
/**
   * Validates the supplied segments.Attempts to determine the path to
   * the controller.
   *
   * @access    private
   * @param    array
   * @return    array
   */   
    function _validate_request($segments)
    {
      // Does the requested controller exist in the root folder?
      if (file_exists(APPPATH.'controllers/'.$segments.EXT))
      {
            return $segments;
      }

      // Is the controller in a sub-folder?
      if (is_dir(APPPATH.'controllers/'.$segments))
      {      
            // Set the directory and remove it from the segment array
            $this->set_directory($segments);
            $segments = array_slice($segments, 1);
            
            if (count($segments) > 0)
            {
                // Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments.EXT))
                {
                  show_404($this->fetch_directory().$segments);
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');
            
                // Does the default controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                  $this->directory = '';
                  return array();
                }
            
            }

            return $segments;
      }

      // Can't find the requested controller...
      show_404($segments);
    }

------------------------------------------------------------------------
这说明什么?   这说明CI 的控制器类的目录不可以有两级或以上的子目录 ,试了一下,果然不行,提示404。
不知哪位有好点的解决方法。

Hex 发表于 2008-10-17 15:29:19

只能是自己扩展这个类,支持多级目录了。

yygcom 发表于 2008-10-17 17:08:38

呵呵,目前还没有用的2级以上的目录,谢谢楼主发现






http://www.jiayuan.com/15284073

visvoy 发表于 2008-12-7 07:15:59

CI的周全判断太保守了,想提速只能自己定制CI,改码

Hex 发表于 2008-12-7 12:09:23

看来是 CI 没注意性能问题?
实际上,扩展这个类就可以实现多级目录了,CI 扩展很容易,并且自己扩展的东西,比别人提供的更好把握。

conqweal 发表于 2010-7-9 22:26:03

放到 application/libaries/下 MY_Router.php
<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package                CodeIgniter
* @author                ExpressionEngine Dev Team
* @copyright        Copyright (c) 2006, EllisLab, Inc.
* @license                http://codeigniter.com/user_guide/license.html
* @link                http://codeigniter.com
* @since                Version 1.0
* @filesource
*/

// ------------------------------------------------------------------------

/**
* MY_Router Class
*
* Parses URIs and determines routing
*
* @package                CodeIgniter
* @subpackage        Libraries
* @author                ExpressionEngine Dev Team
* @category        Libraries
* @link                http://codeigniter.com/user_guide/general/routing.html
*/
class MY_Router extends CI_Router
{
        /**
       * Constructor
       *
       * Runs the route mapping function.
       */
        public function __construct()
        {
                parent::CI_Router();
        }
       
        // --------------------------------------------------------------------
        /**
       * Validates the supplied segments.Attempts to determine the path to
       * the controller.
       *
       * @access        private
       * @param        array
       * @return        array
       */       
        function _validate_request($segments)
        {
                // Does the requested controller exist in the root folder?
                if (file_exists(APPPATH.'controllers/'.$segments.EXT))
                {
                        return $segments;
                }

                // Is the controller in a sub-folder?
                if (is_dir(APPPATH.'controllers/'.$segments))
                {               
                        // Set the directory and remove it from the segment array
                        //$this->set_directory($segments);
                        //$segments = array_slice($segments, 1);
            $tempDir = array();
            $i = 0;

            for(; $i < count($segments); $i++)
            {
                // We keep going until we can't find a directory
                $tempDir[] = $segments[$i];
                if(!is_dir(APPPATH.'/controllers/'.implode('/', $tempDir)))
                {
                  // The last "segment" is not a part of the "directory" so we can get rid of it.
                  unset($tempDir);
                  break;
                }
            }

            $this->set_directory(implode('/', $tempDir));
            $segments = array_slice($segments, $i);

                        if (count($segments) > 0)
                        {
                                // Does the requested controller exist in the sub-folder?
                                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments.EXT))
                                {
                                        show_404($this->fetch_directory().$segments);
                                }
                        }
                        else
                        {
                                $this->set_class($this->default_controller);
                                $this->set_method('index');
                       
                                // Does the default controller exist in the sub-folder?
                                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                                {
                                        $this->directory = '';
                                        return array();
                                }
                       
                        }

                        return $segments;
                }

                // Can't find the requested controller...
                show_404($segments);
        }
}
// END MY_Router Class
页: [1]
查看完整版本: 慢慢地看清CI了 &&&&& 望高人指教