URI段与问号(URI Segment with Question Mark)

2019-09-17 01:02发布

对于我的休息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;

是否有任何其他的可能性,以节省问号整段?

Answer 1:

首先,请确保您有:

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


Answer 2:

在您的配置文件,请确保以下设置为TRUE

$config['allow_get_array']= TRUE;


文章来源: URI Segment with Question Mark