关于CodeIgniter3.0default_controller的疑问
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了关于CodeIgniter3.0default_controller的疑问,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1848字,纯文字阅读大概需要3分钟。
内容图文
![关于CodeIgniter3.0default_controller的疑问](/upload/InfoBanner/zyjiaocheng/238/71e421a572014ebc825f930656c71bb6.jpg)
我在CI2.x的时候,在controller目录下,分别有admin和index两个目录分别对应后台与前台。
那么routes.php中我是这样设置的
$route['default_controller'] = 'index/home/index';
现在发现在3.0中,这样设置不行了。请问我应该怎么做。 比较纠结的是,我确实希望把前台放到index目录下,而不是直接移动到上层的controller里面。
请问,在现有目录结构的情况下,我怎么实现访问index.php的时候默认控制器为index/home/index
另外,不想通过redirect跳转过去,因为这样显示的就不是index.php而是把全路径暴露出来了
回复内容:
我在CI2.x的时候,在controller目录下,分别有admin和index两个目录分别对应后台与前台。
那么routes.php中我是这样设置的
$route['default_controller'] = 'index/home/index';
现在发现在3.0中,这样设置不行了。请问我应该怎么做。 比较纠结的是,我确实希望把前台放到index目录下,而不是直接移动到上层的controller里面。
请问,在现有目录结构的情况下,我怎么实现访问index.php的时候默认控制器为index/home/index
另外,不想通过redirect跳转过去,因为这样显示的就不是index.php而是把全路径暴露出来了
官方文档有说明
Directories and ‘default_controller’, ‘404_override’
As you should know, the $route['default_controller'] and $route['404_override'] settings accept not only a controller name, but also controller/method pairs. However, a bug in the routing logic has made it possible for some users to use that as directory/controller instead.
As already said, this behavior was incidental and was never intended, nor documented. If you’ve relied on it, your application will break with CodeIgniter 3.0.
可见官方其实是把这当成一个BUG的,并不推荐这种做法。
不想显示index.php;应该是配置:config.phg
$config['index_page'] = ''; //去掉index.php
在根目录加入.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
再者你的配置应该是
$route['default_controller'] ='index/home';
内容总结
以上是互联网集市为您收集整理的关于CodeIgniter3.0default_controller的疑问全部内容,希望文章能够帮你解决关于CodeIgniter3.0default_controller的疑问所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。