SEO URIs *AND* $_GET requests - /controller/function/?myvar=1 |
[eluser]Pygon[/eluser]
After being annoyed for the longest time with CI's handling of _GET requests while using SEO friendly URIs, I decided to come up with a solution. So far, I've not run into any problems, however this is fairly fresh and lightly tested. app/lib/MY_URI.php Code: <?php app/lib/MY_Input.php Code: <?php Access as normal using $this->input->get()
[eluser]frenzal[/eluser]
I'll give it a go a later, it's allways handy to have access to GET data especially when dealing with 3rd parties, thanks!
[eluser]jmun[/eluser]
I am trying: http://mydomain/test/form/?myvar=1 Code: function form() But it returns false. Any ideas?
[eluser]xwero[/eluser]
[quote author="jmun" date="1204159789"]I am trying: http://mydomain/test/form/?myvar=1 Code: function form() But it returns false. Any ideas?[/quote] The get method from the input class doesn't mimic the get global. The method retrieves on value based on a key you add as argument. So Code: function form()
[eluser]Lovecannon[/eluser]
It takes one line to enable get...without having to override anything..just add this to anywhere you want $_GET... Code: parse_str($_SERVER['QUERY_STRING'],$_GET);
[eluser]Neophyte[/eluser]
[quote author="Lovecannon" date="1204187790"]It takes one line to enable get...without having to override anything..just add this to anywhere you want $_GET... Code: parse_str($_SERVER['QUERY_STRING'],$_GET); With that approach any URI in the form of /controller/method/?q=Search+Terms+Here will not work as CI will no longer grab the controller and method segments. So you'll probably end up with a 404 error. Pygons approach initially clears any GET data so CI will parse out the segments allowing CIs routing to work as expected then a little further on in execution once CI has decided on all the segments and knows the controller and method to be called the GET data is re-initialised ready for use with the input library.
[eluser]Lovecannon[/eluser]
I use the above parse_str method all the time, and it never causes an error in Codeigniter. It works just fine.
[eluser]jmun[/eluser]
I tried parse_str($_SERVER['QUERY_STRING'],$_GET); in my controller/function and I get a 404 error. I used Pygon's code and it seems to work pretty well.
[eluser]Lovecannon[/eluser]
Well, I bet you have your URI protocol set to AUTO, open your application/config/config.php and change the $config['uri_protocol'] to PATH_INFO, but PATH_INFO is not correctly set if your PHP installation runs on FastCGI, so you could either change PATH_INFO to ORIG_PATH_INFO or add this line to your CI index.php Code: $_SERVER['PATH_INFO'] = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : '';
[eluser]badgeek[/eluser]
i use this on my site, just enable query string on your config Code: RewriteEngine On |
Welcome Guest, Not a member yet? Register Sign In |