带有问号的URI段 [英] URI Segment with Question Mark
问题描述
对于我的休息WebService我需要一些变化,把城市或区域或其他东西。所以我的URI应该是这样:
For my Rest WebService I need some variations to put the city or Region or something else in it. So my URI should look like this:
/rest/rating/locations?city=London
现在我使用以下函数获取最后一个URI段:
Now I'm using following functions to get the last URI Segment:
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
问题是来自问号的所有东西都被切割了!
保存的变量只是:locations
The Problem is here that everthing from the Question Mark gets cutted! The variable which gets saved is just: locations
我已经尝试在config.php配置以下:
I've tried configure following in the config.php:
$config['uri_protocol'] = 'PATH_INFO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';
$config['enable_query_strings'] = TRUE;
是否还有其他可能性用问号保存整个段?
Is there any other possibility to save the whole segment with the question mark?
推荐答案
首先,确保你有:
$config['allow_get_array'] = TRUE;
enable_query_strings
实际上是完全不同的
URI类仍然不能帮助你,你必须单独引用查询字符串。
The URI class still won't help you here, you'll have to refer to the query string separately.
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
// Either of these should work
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
$lastseg_with_query = $lastseg.'?'.$query_string;
这篇关于带有问号的URI段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!