Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用post和get参数的Codeigniter路由_Php_Codeigniter_Codeigniter Url - Fatal编程技术网

Php 使用post和get参数的Codeigniter路由

Php 使用post和get参数的Codeigniter路由,php,codeigniter,codeigniter-url,Php,Codeigniter,Codeigniter Url,我的config/routes.php文件中有以下内容: $route['(:any)]=“仪表板/索引/$1” 当访问以下url时,这将按预期工作:mysite.com/user/id,将调用仪表板控制器中的函数,第一个参数为“user”,第二个参数为“id”。但是,当传递post和get值时,例如mysite.com/user/id?page=2函数似乎忽略post参数,并且第一个(也是唯一一个)参数为“2” My config.php文件具有以下值: $config[‘uri_proto

我的config/routes.php文件中有以下内容:

$route['(:any)]=“仪表板/索引/$1”

当访问以下url时,这将按预期工作:mysite.com/user/id,将调用仪表板控制器中的函数,第一个参数为“user”,第二个参数为“id”。但是,当传递post和get值时,例如mysite.com/user/id?page=2函数似乎忽略post参数,并且第一个(也是唯一一个)参数为“2”

My config.php文件具有以下值:

$config[‘uri_protocol’]  = “AUTO”;
$config[‘enable_query_strings’] = TRUE;

$config['uri_protocol']=“自动”;
$config['enable_query_strings']=TRUE;

和.访问:

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

重新启动发动机
1美元^(index.php | resources | robots.txt)
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L,QSA]


我的路由条件中是否缺少某些内容?

这肯定是您的自定义路由,请尝试yoursite.com/user/id/?page=2,因为我认为字符串id?page=2作为一个参数传递。 您还可以通过打印出传递的url键数组来进行调试:

echo '<pre>'; print_r($this->uri->segment_array()); echo '</pre>' 回声'; 打印($this->uri->segment_array()); 回声“ 您将把所有参数传递给控制器操作。您还可以看到这个答案:关于扩展核心URI类(如果需要)。 我希望这有帮助,否则更多的信息将有帮助,例如,当您使用正常请求(如site.com/user/id)时,控制器中传递的url键是什么?当您执行site.com/user/id?page=2请求时

******编辑********** 如果您使用的是CI 1.7.1或1.7.2,那么您将获得[1]=>页面,因为在_fetch_uri_string方法中,您有如下内容:

if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') { //Comment this line cause you don't need it //$this->uri_string = key($_GET); //fetch the current page number if there is one $page_number = (int) $_GET['page']; //Set the uri_string here with the proper id and pass the id (which you should get here too) and the page number as second parameter then just return; to stop execution further $this->uri_string = 'dashboard/index/id/'.$page_number return; } //In your dashboard controller: //Set default values to 0 and process further public function index($id=0, $page_number=0) { } 如果(is_数组($\u GET)和计数($\u GET)=1和修剪(键($\u GET),“/”)!=“”) { $this->uri\u string=key($\u GET); 返回; } 由于您有site.com/user/id/?page=2,这意味着:$\u GET['page']=2,page是$\u GET中键的名称

请使用上面关于如何在应用程序中扩展此类的链接,并在此处添加您自己的逻辑,例如,类似的内容适用于1.7.1或1.7.2

$page = $this->input->get('page');
如果(is_数组($\u GET)和计数($\u GET)=1和修剪(键($\u GET),“/”)!=“”) { //注释这行,因为您不需要它 //$this->uri\u string=key($\u GET); //获取当前页码(如果有) $page_number=(int)$_GET['page']; //在这里使用正确的id设置uri_字符串,并将id(您也应该在这里获得)和页码作为第二个参数传递,然后返回;以进一步停止执行 $this->uri\u string='dashboard/index/id/'。$page\u编号 返回; } //在仪表板控制器中: //将默认值设置为0并进一步处理 公共功能索引($id=0,$page\u number=0) { }
希望这有帮助

uri段在这里对您没有帮助。 您应该使用获取页面的值

public function index($one = '', $two = '')
{
    echo $one.', '.$two.', ';
    echo '['.$this->input->get('page').']';
}
您的方法接口是什么样子的

我刚试过这个


它输出如下:
user,id,[2]

当我用mysite.com/user/id/?page=2打印通过的url键数组时,我只得到1个值:
[1]=>page
对于mysite.com/user/id/我得到2个值:
[1]=>user[2]=>id
还有
$config['enable\u query\u strings']
标志设置为TRUE@xylar看看这里的解决方案,它应该已经解决了你的问题,如果是这样的话,请允许zokibtmkd获得荣誉,他似乎超越了帮助。如果不让我们知道,也许我们可以进一步帮助。
public function index($one = '', $two = '')
{
    echo $one.', '.$two.', ';
    echo '['.$this->input->get('page').']';
}