URI Segment with Question Mark

2019-07-17 01:49发布

问题:

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

Now I'm using following functions to get the last URI Segment:

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

The Problem is here that everthing from the Question Mark gets cutted! The variable which gets saved is just: locations

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?

回答1:

First, make sure you have:

$config['allow_get_array'] = TRUE;

enable_query_strings is actually something else entirely, an old feature that's not used much.

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;


回答2:

In your config file, make sure the following is set as TRUE:

$config['allow_get_array']= TRUE;