带有问号的URI段

时间:2012-05-05 18:49:17

标签: codeigniter uri

对于我的Rest WebService,我需要一些变体来将城市或地区或其他内容放入其中。所以我的URI应该是这样的:

/rest/rating/locations?city=London

现在我正在使用以下函数来获取最后一个URI段:

$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);

这里的问题是从问号中删除了! 保存的变量只是:位置

我在config.php中尝试过配置:

$config['uri_protocol'] = 'PATH_INFO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';
$config['enable_query_strings'] = TRUE;

还有其他可能用问号保存整个片段吗?

2 个答案:

答案 0 :(得分:2)

首先,请确保您拥有:

$config['allow_get_array'] = TRUE;

enable_query_strings实际上是完全不同的东西,这是一个使用不多的旧功能。

URI类仍然无法帮助您,您必须单独引用查询字符串。

$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;

答案 1 :(得分:0)

在配置文件中,确保将以下内容设置为TRUE

$config['allow_get_array']= TRUE;
相关问题