在 codeigniter 中启用 $_GET [英] Enabling $_GET in codeigniter

查看:20
本文介绍了在 codeigniter 中启用 $_GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想如何在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆