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

[控制器] CI3.0默认控制器和404_override不生效的解决办法

[复制链接]
发表于 2015-8-4 16:48:57 | 显示全部楼层 |阅读模式
CI3.0
config.php 里的设置:
$config['enable_query_strings'] = TRUE;
的时候,routes.php里的:
$route['default_controller'] = 'Information/page_missing';
$route['404_override'] = 'Information/page_missing';

均不生效,
查找到源码:
system/core/Route.php 里的 _set_routing() 方法,发现:
if ($this->enable_query_strings) 的时候,没有加载:routes.php文件,解决办法,将下面代码从中间挪到方法最开始位置:
                // Load the routes.php file.
                if (file_exists(APPPATH.'config/routes.php'))
                {
                        include(APPPATH.'config/routes.php');
                }

                if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
                {
                        include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
                }

                // Validate & get reserved routes
                if (isset($route) && is_array($route))
                {
                        isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
                        isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
                        unset($route['default_controller'], $route['translate_uri_dashes']);
                        $this->routes = $route;
                }

本版积分规则