Welcome Guest, Not a member yet? Register   Sign In
Empty _GET array - unable to retrieve a 'get' variable
#1

[eluser]passenger[/eluser]
I am unable to retrieve a variable passed using GET syntax:

Code:
http://www.domain.com/callback?foo=something
Here is my controller:

Code:
class Callback extends Controller {

    function Callback()
    {    
        parent::Controller();

    }
    
    function success () {
        $incoming=$this->input->get('foo');
        if ($incoming) {
            echo "incoming=".$incoming;
        } else {
           echo "no incoming (".$incoming.")";
           print_r($_GET);
        }
    }        
}
When I use the URL example above, the code displays:

Code:
no incoming ()Array ( )

This suggests that there is nothing in the GET array, although I think this is cleared by the input class. Nevertheless, I can't seem to get the value passed in the URL.

In the config, I've set 'enable_query_strings' to be TRUE, but this makes no difference.

None of my routes match this pattern, so it can't be that, and here is my .htaccess.

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css/styles\.css)
RewriteRule ^(.*)$ /index.php?/$1 [L]

Any ideas?
#2

[eluser]missionsix[/eluser]
have you enabled query strings in config.php?

You might have to change your routing method from AUTO to something else as well.
#3

[eluser]passenger[/eluser]
Hi MS:

1) Query Strings

Yes. As I said in the original post:

Quote:In the config, I’ve set ‘enable_query_strings’ to be TRUE, but this makes no difference.


:-)

Change your routing method

What do you mean? Do you mean the "uri_protocol" in the config. If so, this no help - if I use anything other than AUTO in the URI Protocol, other areas of the site break. I am reticent to rewrite the site to work with a single method alone.

So, no help I'm afraid - thanks anyway.

This has me beaten for the moment, and I am now going to have to write a standalone PHP script to handle GETs, outside of CI. Which is a shame because I am sure CI can handle this, and I am thoroughly enjoying all other aspects of the framework!

If anyone can post an example of using gets within a controller, and any config settings that are required, this might get me going.

Thanks.
#4

[eluser]missionsix[/eluser]
Do you need GET's?


You can use the URI->segment() method to pull out parts of the url.

so you can do:

Code:
/controller/method/foo/bar/

And you can access the other segments with: $this->uri->segment(3) , for foo, and $this->uri->segment(4), for bar. This probably doesn't help you though.




In order to get Query Strings working on my box, i had to use this config setting:

Code:
$config['uri_protocol']    = "ORIG_PATH_INFO";

And then in my controller I used $_GET directly.
#5

[eluser]Colin Williams[/eluser]
I've got query strings enabled and use uri protocol PATH_INFO or REQUEST_URI and it works just fine on all my projects. Your problem is elsewhere, possibly something with mod_rewrite rules
#6

[eluser]passenger[/eluser]
[quote author="Colin Williams" date="1218597165"]I've got query strings enabled and use uri protocol PATH_INFO or REQUEST_URI and it works just fine on all my projects. Your problem is elsewhere, possibly something with mod_rewrite rules[/quote]

Thanks Colin,

Any chance you could post a simple, working example.

No need to post the config as long as these are the only changes from base CI, and there are no routes/.htaccess in play.

Thanks if you can,

C
#7

[eluser]Colin Williams[/eluser]
Umm... sure...

Code:
print $_GET['q'];

and the config, just to be clear:

Code:
$config['uri_protocol']    = "PATH_INFO";
$config['enable_query_strings'] = TRUE;

No .htaccess, no routing, and when I hit up http://localhost/index.php/test/?q=hello or even http://localhost/index.php/test?q=hello I see:

Quote:hello

CI 1.6.3
#8

[eluser]Colin Williams[/eluser]
Ugh.. I can see the error with your .htaccess right away

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css/styles\.css)
RewriteRule ^(.*)$ /index.php?/$1 [L]

You have RewriteRule ^(.*)$ /index.php?/$1... see the index.php?/$1? Your rewrite is passing the whole path as a query string key. Just drop the ? Do RewriteRule ^(.*)$ /index.php/$1 [L] instead.

Also, your third RewriteCond COMPLETELY NEGATES the previous two RewriteConds




Theme © iAndrew 2016 - Forum software by © MyBB