Welcome Guest, Not a member yet? Register   Sign In
How I got around $_GET restrictions
#1

[eluser]Unknown[/eluser]
I wanted to use get vars but didn't want to make some crappy URL like

index.php?c=bla&m=bla

This is used for search results in my app so I can keep it pretty

http://www.mysite.com/search/?q=someurlencodedstuff

Here is the simple code I put in my model that handles search results

Here is how i did it recently. I'm sure it will piss off some purists, but google search indicates that people really want to be able to use CI with a feature like this... so this is an easy "in place" solution you can use

Code:
<?php
//adapt this code for your own use
                //added example.com to satisfy parse_url
        $url="http://www.example.com".$_SERVER["REQUEST_URI"];
        $url=parse_url($url);
                //I'm expecting variables so if they aren't there send them to the homepage
        if (!array_key_exists('query',$url))
        {

             redirect('/'); exit;
        }
        $query=$url['query'];
        
        parse_str($query,$_GET); //add to $_GET global array
        
        var_dump($_GET);
?>
#2

[eluser]ChrisMiller[/eluser]
Or you could just change your config variable uri_protocol from auto to paht info
Code:
$config['uri_protocol']    = 'PATH_INFO';

and then add this to your controller or wherever you want to repopulate the _GET variable
Code:
parse_str($_SERVER['QUERY_STRING'],$_GET);
var_dump($_GET);

But your way is just a lil longer thats all....
#3

[eluser]Unknown[/eluser]
thanks for the reply... what does "PATH_INFO" uri_protocol enable?

I'm concerned it would have unforeseen consequences

thanks, if it works in my scenario i think it might be OK but i want all the other urls existing to work the normal way... just using $_GET for search page only
#4

[eluser]ChrisMiller[/eluser]
[quote author="ladieu" date="1302001494"]thanks for the reply... what does "PATH_INFO" uri_protocol enable?

I'm concerned it would have unforeseen consequences
[/quote]

As far as I know it really has no effect at all in regards to unforseen consequences it just changes the way codeigniter interperts urls. I had to change that before to keep the urls from getting buggy on me. It is used on a production server now for several months, if not over a year and no problems at all.




Theme © iAndrew 2016 - Forum software by © MyBB