代码之家  ›  专栏  ›  技术社区  ›  Nir Gavish

启用$\u进入编码器点火器

  •  11
  • Nir Gavish  · 技术社区  · 15 年前

    我一直在努力想办法让$\u进入CI。

    框架似乎故意破坏了$\u get数组,启用它需要对核心类进行认真的修补。有人能说出这是为什么,以及如何克服它吗?

    请注意,我希望保持URI解析和路由的方式不变,只需让$\u也可用即可。

    7 回复  |  直到 13 年前
        1
  •  14
  •   Stephen Curran    15 年前

    将以下库添加到应用程序库中。它会覆盖默认输入库的行为,以清除$\u get数组。它允许混合使用uri段和查询字符串。

    应用程序/库/my_input.php

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

    还需要修改一些配置设置。需要将uri_协议设置更改为路径_信息和“?”需要将字符添加到URI中允许的字符列表中。

    应用程序/config/config.php

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

    然后可以访问通过查询字符串传入的值。

    $this->input->get('x');
    
        2
  •  9
  •   Gordon Haim Evgi    15 年前

    CodeIgniter's manual about security :

    获取、发布和cookie数据

    获取数据被 由于系统利用了 URI段而不是传统的 URL查询字符串(除非 在您的 配置文件)。全局get数组是 在系统中由输入类取消设置 初始化。

    通读这个 forum entry for possible solutions ( 从第1页的下半部分开始变得有趣 )

        3
  •  2
  •   Community Mohan Dere    8 年前

    我没有足够的声誉发表评论,但是 Phil Sturgeon's answer above 如果切换到 Codeigniter Reactor 对你来说很容易。

    您可以使用$GET或$THIS->INPUT->GET()访问查询字符串,而无需使用“我的输入”覆盖,甚至无需更改config.php文件。

        4
  •  1
  •   Andreas Gohr    13 年前

    我在控制器中成功地使用了这条单线。它基本上是在不依赖任何特殊的codeigner设置的情况下重新处理请求URL:

    parse_str(array_pop(explode('?',$_SERVER['REQUEST_URI'],2)),$_GET);

        5
  •  1
  •   Abdul Rahman Rodrigo    13 年前

    在服务器上,没有 PATH_INFO (和我一样)试试这个:

    parse_str(substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'],'?')+1,strlen($_SERVER['REQUEST_URI'])-strpos($_SERVER['REQUEST_URI'],'?')),$_GET);
    

    你可以这样说:

    class Your_controller extends Controller {
    
    function Your_controller()
    {
        parent::Controller();
    
        date_default_timezone_set('Asia/Jakarta'); // set my timezone
    
        parse_str(substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'],'?')+1,strlen($_SERVER['REQUEST_URI'])-strpos($_SERVER['REQUEST_URI'],'?')),$_GET);
    
    }
    
    function test()
    {
        print_r($_GET); // here your $_GET vars
    }
    
    }
    
        6
  •  0
  •   itsme    13 年前

    从未使用过带有CI的$\u get,最好将脚本逻辑更改为使用post或$this->uri->segment(),然后更改为active$\u get params for me

        7
  •  0
  •   Community Mohan Dere    8 年前

    发件人: CodeIgniter PHP Framework - Need to get query string

    下面是一个完整的工作示例,说明如何在代码点火器中允许查询字符串,就像在Jrox平台上一样。只需将其添加到位于以下位置的config.php文件中:

    /system/application/config/config.php 
    

    然后,您可以使用$\u get或下面的类简单地获得像normal一样的查询字符串。

    $yo = $this->input->get('some_querystring', TRUE);
    $yo = $_GET['some_querystring'];
    

    以下是使一切正常运行的代码:

    /*
    |--------------------------------------------------------------------------
    | Enable Full Query Strings (allow querstrings) USE ALL CODES BELOW
    |--------------------------------------------------------------------------*/
    
    /*
    |----------------------------------------------------------------------
    | URI PROTOCOL
    |----------------------------------------------------------------------
    |
    | This item determines which server global should 
    | be used to retrieve the URI string.  The default 
    | setting of 'AUTO' works for most servers.
    | If your links do not seem to work, try one of 
    | the other delicious flavors:
    |
    | 'AUTO'              Default - auto detects
    | 'PATH_INFO'         Uses the PATH_INFO
    | 'QUERY_STRING'      Uses the QUERY_STRING
    | 'REQUEST_URI'   Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'    Uses the ORIG_PATH_INFO
    |
    */
    if (empty($_SERVER['PATH_INFO'])) {
        $pathInfo = $_SERVER['REQUEST_URI'];
        $index = strpos($pathInfo, '?');
        if ($index !== false) {
            $pathInfo = substr($pathInfo, 0, $index);
        }
        $_SERVER['PATH_INFO'] = $pathInfo;
    }
    
    $config['uri_protocol'] = 'PATH_INFO'; // allow all characters 
    
    $config['permitted_uri_chars'] = ''; // allow all characters 
    
    $config['enable_query_strings'] = TRUE; // allow all characters 
    
    parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
    

    享受:-

    推荐文章