在codeigniter中启用$ _GET [英] Enabling $_GET in codeigniter
问题描述
我一直在尝试弄清楚如何在CI中启用$ _GET。
I've been trying to figure out how to enable $_GET in CI.
框架故意销毁$ _GET数组,严重修改核心类。可以任何人说为什么这是,以及如何克服它?
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?
记住你,我想保持URI解析和路由方式,只是简单地有$ _GET。
mind you, i'm looking to keep URI parsing and routing the way they are, just simply have the $_GET available as well.
推荐答案
将以下库添加到应用程序库。它覆盖清除$ _GET数组的默认输入库的行为。它允许混合使用URI段和查询字符串。
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();
}
}
它还需要修改一些配置设置。 uri_protocol设置需要更改为PATH_INFO,并且需要将?字符添加到URI中允许的字符列表中。
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');
这篇关于在codeigniter中启用$ _GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!