1

Is there a way to enable query string in just one controller or for one function. For example, I want to use query string in search function, and segments in every other.

Is there a way to do this?

Can I do something like this:

$this->config->set_item('uri_protocol', 'PATH_INFO');
$this->config->set_item('enable_query_strings', TRUE);
2
  • Why do you want to use query strings in the first place? You can pass data the CI way using segments rather than query strings. example.com?first=cheese&second=pizza is done like this the CI way - example.com/controller/method/cheese/pizza. Commented Apr 27, 2012 at 21:31
  • p.s. welcome to stack overflow. Commented Apr 27, 2012 at 21:32

1 Answer 1

5

A simple way to achieve this is by parsing the server query string like so.

$get_data = array();

parse_str($_SERVER['QUERY_STRING'], $get_data);

This will leave you with a very insecure array full of data, so you should use CI's security class to make it more secure; so like;

$get_data = $this->security->xss_clean($get_data);

This will not mean that routing works via GET, only allow you to get the GET vars safely.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. This answer saved me from several really bad alternatives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.