Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been trying to figure out how to enable $_GET in CI.

It appears the framework deliberately destroys the $_GET array, and that enabling it requires serious tinkering with the core classes. can anyone say why this is, and how to overcome it?

mind you, i'm looking to keep URI parsing and routing the way they are, just simply have the $_GET available as well.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
248 views
Welcome To Ask or Share your Answers For Others

1 Answer

Add the following library to your application libraries. It overrides the behaviour of the default Input library of clearing the $_GET array. It allows for a mixture of URI segments and query string.

application/libraries/MY_Input.php

class MY_Input extends CI_Input 
{
    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }
}

Its also necessary to modify some configuration settings. The uri_protocol setting needs to be changed to PATH_INFO and the '?' character needs to be added to the list of allowed characters in the URI.

application/config/config.php

$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-?';

It is then possible to access values passed in through the query string.

$this->input->get('x');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...