Welcome Guest, Not a member yet? Register   Sign In
INPUT CLASS destroys global get?
#1

[eluser]RJ[/eluser]
Quote:Destroys the global GET array. Since CodeIgniter does not utilize GET strings, there is no reason to allow it.

Found this is the user guide under http://ellislab.com/codeigniter/user-gui...input.html; further down on the page they provide methods to grab GET data. My question is, can I access a GET string?

Thank you!

bs
#2

[eluser]xwero[/eluser]
yes CI cleans the GET global but it leaves the SERVER['QUERY_STRING'] alone so all you have to do is
Code:
$_GET = parse_str($_SERVER['QUERY_STRING']);

And then you can even use the CI uri methods afterwards.
#3

[eluser]RJ[/eluser]
So it will take:
Code:
?Type=whatever&people=model


And place into that into Server query string? Any idea if there are string size limitations to this?

I am working with an old scripting system and they are transferring data using GET quite a bit. Will try to get away from soon.

Thanks
#4

[eluser]xwero[/eluser]
yes but you can't use the auto uri_protocol because this will try to process the query string in certain circumstances.
#5

[eluser]RJ[/eluser]
I can't auto-load the uri library if i'm trying to access the get string?
#6

[eluser]moodh[/eluser]
[quote author="bullspit" date="1239164450"]I can't auto-load the uri library if i'm trying to access the get string?[/quote]

The URI library is loaded by default.
#7

[eluser]Colin Williams[/eluser]
[quote author="bullspit" date="1239160864"]So it will take:
Code:
?Type=whatever&people=model


And place into that into Server query string?[/quote]

Well, that server variable is available whether or not you use CI. xwero just shows you how to repopulate the $_GET superglobal by parsing this environment variable.
#8

[eluser]xwero[/eluser]
Colin thank you for putting my code snippet into context.

The SERVER query_string is generated by the sever upon the request that has been received, just like GET but that global puts the query_string in an easier to use array. The parse_str function is like a specialised explode function because it will break the query string like you are used to receive GET and POST input.

Oops the use of the parse_str function is wrong, it has to be
Code:
parse_str($_SERVER['QUERY_STRING'],$_GET);
#9

[eluser]judico[/eluser]
Here is my solution to the occasional need to acquire a querystring parameter value from a GET request.

Note: $config['enable_query_strings'] = FALSE; in my config.php

Code:
/**
*url querystring parameter
*ADDED to CI url_helper.php by Kevin Davis 4/10/09
*retrieve a querystring value from a GET request
*
*Location: ./system/helpers/url_helper.php
*
*@access public
*@param string
*@return string
*/
if ( ! function_exists('querystring_get_param_value'))
{
    function querystring_get_param_value($key)
    {
        //This codeblock acquires a querystring value from the $_SERVER array.
        preg_match("/[?&]" . $key . "=([^&$]*)/", $_SERVER['REQUEST_URI'], $matches);

        if(count($matches) == 2){
            $value = urldecode($matches[1]);
        }
        else{
            $value = '';
        }
        
        return $phrase;
    }
}


//after adding this function to url_helper.php you can simply do the following

$value = querystring_get_param_value('txt');

//$value will equal 'foo' for something like example.com/sample?txt=foo

//Hope someone finds this useful.
#10

[eluser]xwero[/eluser]
judico doing a preg_match for every value you have to get is more expensive than parsing the query string once and putting it in a variable, it doesn't have to be the get global.




Theme © iAndrew 2016 - Forum software by © MyBB