问题描述
在CodeIgniter中,将URI段和查询字符串同时合并是非常棘手的。
几乎实现的一个传统方法是启用 enable_query_strings
。
In CodeIgniter it's really tricky to combine URI segments and Query strings at the same time.One of the traditional ways to almost achieve that is by enabling enable_query_strings
.
问题是
通过使用例子: redirect('/ home')
By example when using: redirect('/home')
it redirects to domain.com/?/home
.
根据我的知识, code> enable_query_strings 不是用于URI段。
Based on my knowledge, enable_query_strings
is not meant to be used with URI segments.
因此如何扩展核心以启用GET和URI开箱即用?
So how to extend the core to enable both GET and URI out of the box?
PS我知道最好只是使用URI段,但有时接受来自adwords的GET查询非常重要。
推荐答案
最佳解决方案是:
- 确保您使用的是最新版本的CI,目前为2.0.2
- 忘记误导的
enable_query_strings
(这不是你想要的) - 打开你的配置文件并设置
$
到
TRUE
,这将允许您使用$ _ GET
- 使用
uri_protocol
设置,直到找到适合您的环境的PATH_INFO $ c
- Make sure you are on the latest version of CI, currently 2.0.2
- Forget about the misleading
enable_query_strings
(it's not what you want) - Open your config file and set
allow_get_array
toTRUE
, which will allow you to use$_GET
- Play with the
uri_protocol
setting until you find one that works for your environment,PATH_INFO
works for me. - Enjoy the use of proper query strings!
enable_query_strings 几乎打破了Codeigniter的所有功能,包括处理urls的帮助函数,包括 all 。
enable_query_strings
breaks almost all the functionality that makes Codeigniter great, including all the helper functions that deal with urls. It was some experimental feature that has been confused with normal query string support for as long as CI has been around.
底线 - 只是升级(如果你还没有) ),并且不要试图为它写一个黑客。
Bottom line - just upgrade (if you haven't already) and don't try to write a hack for it.
这篇关于如何使用URI段和查询字符串,而不启用:enable_query_strings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!