![]() |
Simple Query String Handler - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Simple Query String Handler (/showthread.php?tid=37222) |
Simple Query String Handler - El Forum - 01-02-2011 [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. Simple Query String Handler - El Forum - 01-04-2011 [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. Simple Query String Handler - El Forum - 01-05-2011 [eluser]Tominator[/eluser] $this->input->get() is not working for you? Simple Query String Handler - El Forum - 01-05-2011 [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. Simple Query String Handler - El Forum - 03-04-2011 [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 { |