简体   繁体   English

如何使用Codeigniter(而不使用querystring)将复杂的$ _GET变量检索为多维数组

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

** I've googled for hours, and searched within stackoverflow. **我已经搜索了几个小时,并在stackoverflow中进行了搜索。 Found a few similar ones, but couldn't find a good answer yet.** 找到了一些类似的答案,但找不到很好的答案。**

I'm thinking of rewriting my project using codeigniter. 我正在考虑使用codeigniter重写我的项目。

I have a search.php with possible querystring: 我有一个带有可能的querystring的search.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

Please note that $_GET['i'] & $_GET['d'] could be arrays. 请注意,$ _GET ['i']和$ _GET ['d']可以是数组。

I found some mentioned about 我发现有人提到

$this->url->uri_to_assoc();

Hoping I maybe able to retrieve $_GET values as 希望我可以检索$ _GET值作为

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

or 要么

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

So I tested with controllers/show.php 所以我用controllers / show.php进行了测试

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

When I input in URL as the following, 当我在URL中输入以下内容时,

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

The above code only returns the last input. 上面的代码仅返回最后一个输入。

Array
(
    [i] => l2
)

My actual question is, in Codeigniter, from URL above, is there a way to retrieve as an array as 我的实际问题是,在Codeigniter中,从上面的URL中可以找到一种作为数组的方式

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

or similar NOT using Querystring? 或类似的不使用Querystring? (cos if I enable Querystring I can't use other Codeigniter helping features etc.) (因为我启用了查询字符串,所以我无法使用其他Codeigniter帮助功能等。)

So I could retrieve my original $_GET querystring as something like 所以我可以像这样检索我原来的$ _GET查询字符串

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

in Codeigniter. 在Codeigniter中。

Have you tried using the raw PHP query string? 您是否尝试过使用原始PHP查询字符串?

$_SERVER['QUERY_STRING']

Then phase through it 然后逐步进行

$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
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM