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.
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.