如何使用代码点火器(不使用查询字符串)将复杂的 $_GET 变量检索为多维数组


How to retrieve a complex $_GET variables as a multi-dimensional array using codeigniter (not using querystring)

** 我已经用谷歌搜索了几个小时,并在stackoverflow中搜索。找到了一些类似的,但还找不到好的答案。

我正在考虑使用代码点火器重写我的项目。

我有一个搜索.php可能的查询字符串:

search.php?o=1&kk=1&k=sales&kx=&w=4&l=New+York%2C+NY%2C+USA&i=222&i=229&i=225&i=238&i=237&i=203&el=3&eu=10&ei=on&d=5&d=4&d=9&d=6&at=&a=Any

请注意,$_GET['i'] 和 $_GET['d'] 可以是数组。

我发现一些提到

$this->url->uri_to_assoc();

希望我能够检索 $_GET 值作为

/i/222/i/229/i/225/i/238/i/237/i/203

/i/222/229/225/238/237/203

所以我用控制器/显示.php

class show extends CI_Controller
{
    function get()
    {
        echo "<pre>";
        print_r ($this->uri->uri_to_assoc());
        echo "</pre>";
    }
}

当我输入如下网址时,

http://localhost/index.php/show/get/i/0123/i/52/i/l2

上面的代码仅返回最后一个输入。

Array
(
    [i] => l2
)

我的实际问题是,在Codeigniter中,从上面的 URL 中,有没有办法作为数组检索为

Array
(
[i] => array ([0] => 0123, [1] => 52, [2] => 12)
)

或类似的不使用查询字符串?(因为如果我启用查询字符串,我无法使用其他 Codeigniter 帮助功能等)

所以我可以检索我的原始 $_GET 查询字符串,如下所示

Array
(
[d] => array ([0] => 123, [1] => 456),
[i] => array ([0] => 11, [1] => 99),
[dx] => 1,
[dy] => 'New+York'
)

在代码点火器中。

您是否尝试过使用原始 PHP 查询字符串?

$_SERVER['QUERY_STRING']

然后分阶段通过它

$vars=$_SERVER['QUERY_STRING'];
$vars=explode('&',$vars);
$d=array();
$i=array();
foreach($vars as $var)
{
   $split=explode('=',$var);
   if($split[0]=='d')
   {
       $d[]=$split[1];
   }
   elseif($split[0]=='i')
   {
       $i[]=$split[1];
   }
   else
   {
        $$split[0]=split[1];// note the double $$ signs
   }
}