4

In CodeIgniter it's really tricky to combine URI segments and Query strings at the same time. One of the traditional ways to almost achieve that is by enabling enable_query_strings.

The issue is that this has some weird behavior and it affects all the URL helpers as well.

By example when using: redirect('/home') it redirects to domain.com/?/home.

Based on my knowledge, enable_query_strings is not meant to be used with URI segments.

So how to extend the core to enable both GET and URI out of the box?

P.S. I know that it's better to just use URI segments, but it's very important sometimes to accept GET queries like from adwords.

1
  • 1
    I'm right there with you, sometimes you need $_GET. There's nothing at all wrong with "mixing" it with uri segments. Example: I want people to be able to link to search results that use a search term, entered by the user. How else could you support this if the user input contain characters not in your permitted_uri_chars? How about dealing with third-party responses that use $_GET? You need it sometimes, I have no idea why it was ever disabled in the first place. Commented Jul 14, 2011 at 16:04

1 Answer 1

4

The best solution is this:

  • Make sure you are on the latest version of CI, currently 2.0.2
  • Forget about the misleading enable_query_strings (it's not what you want)
  • Open your config file and set allow_get_array to TRUE, which will allow you to use $_GET
  • Play with the uri_protocol setting until you find one that works for your environment, PATH_INFO works for me.
  • Enjoy the use of proper query strings!

enable_query_strings breaks almost all the functionality that makes Codeigniter great, including all the helper functions that deal with urls. It was some experimental feature that has been confused with normal query string support for as long as CI has been around.

Bottom line - just upgrade (if you haven't already) and don't try to write a hack for it.

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

1 Comment

I need to be able to use the helpers (so I can have domain.com/user/account/edit) but also require the use of the query strings for accessing controllers and methods (domain.com?d=user&c=account&m=edit). Setting enable_query_strings to FALSE means I cannot use the latter at all, despite allow_get_array being TRUE. Is there a way I can huse both options and the URL helpers? (To add, I know the query strings can be used still when enable_query_strings is set to FALSE, but it seems to redirect to the URI version, which I don't want to happen)

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.