Simple Query String Handler |
[eluser]virexmachina[/eluser]
After searching through the forums and wiki for a simple way to handle query strings in CI, I ended up writing a simple helper. I only needed to receive a query string on one page, so I didn't want to have to enable hooks, change uri_protocol or anything. This is good for cases where you need to get query strings on a page or two, like a search page or confirmations from payment gateways. Anyway, here's a simple way to access the query string from any controller: Code: // for example, we're calling foo.com/search/?term=foo&bar=goo&baz; I tried to follow CI Input class conventions of returning null for variables that do not exist. I also return true if a var is provided with no value. Download the helper to application/helpers and you're ready to go. I adapted a loop from Dan Horrigan's CodeIgniter Query String hook to look for the query string in a few places. Corrections and suggestions are very welcome.
[eluser]Nick_MyShuitings[/eluser]
Congrats, I'll point a friend of mine to it, he was fighting with this and hacked something up to work with Twitter oAuth... should be interesting to see his comparison.
[eluser]virexmachina[/eluser]
[quote author="Tominator" date="1294263180"]$this->input->get() is not working for you?[/quote] Nope, it doesn't work on Windows/Apache or CentOS/Apache for me.
[eluser]Miroslav Milic[/eluser]
I had the same problem. Thing is that Input library is destroying $_GET array when enable_query_strings is set to false and that is the case with standard CI configuration. If you want to use $this->input->get() and $this->input->get_post() you can extend Input library with this code: Code: class MY_Input extends CI_Input { |
Welcome Guest, Not a member yet? Register Sign In |