CodeIgniter 从 2.2.0 升级到 3.0.x:只有默认控制器正在加载
CodeIgniter upgrade from 2.2.0 to 3.0.x: Only the default controller is loading
我通常 post 不会在网上发消息寻求帮助,但我觉得我已经尝试了所有方法,但还是卡住了。
我想将 CodeIgniter 从 2.2 版本升级到 3.0.3 版本(我也尝试过 v3.0.2),然后按照相应的 guide on codeigniter.com 进行操作。但是现在,无论 url.
只加载默认控制器
我在网上搜索了一下,发现可能来自:
- htaccess
- application/config/config 文件
- application/config/routes 文件
- 文件名(控制器、型号...)的新 Ucfirst 规则
但是我还是没有解决办法...
- "applications/controllers"里面的文件都是Ucfirst.
- 之前一切正常(使用 2.2 版),因此应该正确配置 WAMP(mod_rewrite 启用等...)。此外,我已经尝试并成功加载了一个干净的 CodeIgniter 3 实例。
- 模型、控制器和视图已正确加载,我可以更改我的默认控制器,它将加载正确的视图(控制器和模型完成请求)。但它只加载默认控制器,无论 url 是什么(在浏览器中)。即使它不存在,我也从来没有 404 页面。除非我指定了不正确的 "default_controller"(在文件 "routes.php" 中)。
一定是路由问题...
以下是我做过的一些测试:
Table of tests
这是我的htaccess文件(我也试过网上其他的,结果是一样的):
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/ [L]
这是我的 "application/config/routes" 文件:
$route['default_controller'] = 'dashboard';
$route['404_override'] = 'auth/e404';
$route['translate_uri_dashes'] = FALSE;
任何帮助将不胜感激:-)
谢谢!
解决方案
$config['enable_query_strings'] 在文件 "application/config/config.php" 中设置为 "TRUE"。将它设置为 "FALSE" 解决了这个问题。就这么简单...
在 codeigniter 3 wamp 中
我用这个 htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
由于你的错误 404 over ride 不能在子文件夹中。
改变
$route['404_override'] = 'auth/e404';
到
$route['404_override'] = 'e404';
然后 config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
尝试将索引方法放在路由中,例如而不是这个
$route['blog'] = 'blog';
试试这个
$route['blog'] = 'blog/index';
如果这不起作用,你能确认你在 application/config/config.php 中设置了正确的基数 url 吗?
我通常 post 不会在网上发消息寻求帮助,但我觉得我已经尝试了所有方法,但还是卡住了。
我想将 CodeIgniter 从 2.2 版本升级到 3.0.3 版本(我也尝试过 v3.0.2),然后按照相应的 guide on codeigniter.com 进行操作。但是现在,无论 url.
只加载默认控制器我在网上搜索了一下,发现可能来自:
- htaccess
- application/config/config 文件
- application/config/routes 文件
- 文件名(控制器、型号...)的新 Ucfirst 规则
但是我还是没有解决办法...
- "applications/controllers"里面的文件都是Ucfirst.
- 之前一切正常(使用 2.2 版),因此应该正确配置 WAMP(mod_rewrite 启用等...)。此外,我已经尝试并成功加载了一个干净的 CodeIgniter 3 实例。
- 模型、控制器和视图已正确加载,我可以更改我的默认控制器,它将加载正确的视图(控制器和模型完成请求)。但它只加载默认控制器,无论 url 是什么(在浏览器中)。即使它不存在,我也从来没有 404 页面。除非我指定了不正确的 "default_controller"(在文件 "routes.php" 中)。
一定是路由问题...
以下是我做过的一些测试: Table of tests
这是我的htaccess文件(我也试过网上其他的,结果是一样的):
RewriteEngine On #Checks to see if the user is attempting to access a valid file, RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #Enable access to the images and css folders, and the robots.txt file RewriteCond !^(index\.php|public|images|robots\.txt|css) RewriteRule ^(.*)$ index.php/ [L]
这是我的 "application/config/routes" 文件:
$route['default_controller'] = 'dashboard'; $route['404_override'] = 'auth/e404'; $route['translate_uri_dashes'] = FALSE;
任何帮助将不胜感激:-)
谢谢!
解决方案
$config['enable_query_strings'] 在文件 "application/config/config.php" 中设置为 "TRUE"。将它设置为 "FALSE" 解决了这个问题。就这么简单...
在 codeigniter 3 wamp 中
我用这个 htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
由于你的错误 404 over ride 不能在子文件夹中。
改变
$route['404_override'] = 'auth/e404';
到
$route['404_override'] = 'e404';
然后 config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
尝试将索引方法放在路由中,例如而不是这个
$route['blog'] = 'blog';
试试这个
$route['blog'] = 'blog/index';
如果这不起作用,你能确认你在 application/config/config.php 中设置了正确的基数 url 吗?