php - URI segment does not get returned when using querystrings
I'm trying to paginate the search results returned by the query. I have the following URL:
Where I am trying to get the value of
$start=5 from the URL using:
$start = $this->uri->segment(3);
It is not returning anything.
blog/search/5 works fine. But I want to keep the query parameter and read the value.
That's because of the
?character in the URI. CodeIgniter URI parser (and any other standard URI parser) does not recognize what you have in mind. After the
?character, it's all query string, not URI segments. See the output of PHP's
See? The first segment is
blog, the second is
searchand the rest is the querystring.
You need to change your URI design in an standard way. For example:
So that the call to
$this->uri->segment(3)will return what you have in mind.
Speaking of CodeIgniter pagination library, see
page_query_stringconfigs in the documentation.