CakePHP在Controller::redirect中传递参数

CakePHP在Controller::redirect中传递参数,php,cakephp,redirect,cakephp-2.0,Php,Cakephp,Redirect,Cakephp 2.0,在控制器执行重定向操作时,我使用以下命令: $this->redirect(array('controller' => 'tools', 'action' => 'index')); $this->redirect('tools/index/?myArgument=12'); 还是这个 $this->redirect('/tools/index'); 当我通过重定向传递数据时,我使用以下方法: $this->redirect(array('control

在控制器执行重定向操作时,我使用以下命令:

$this->redirect(array('controller' => 'tools', 'action' => 'index'));
$this->redirect('tools/index/?myArgument=12');
还是这个

$this->redirect('/tools/index');
当我通过重定向传递数据时,我使用以下方法:

$this->redirect(array('controller' => 'tools', 'action' => 'index'));
$this->redirect('tools/index/?myArgument=12');
但是我找不到如何通过“this redirect array”符号传递“myargument”。
我不想使用此选项,因为存在一些路由问题:

$this->redirect(array('controller' => 'tools', 'action' => 'index', "myArgument"));
我需要这样的东西:

$this->redirect(array('controller' => 'tools', 'action' => 'index', "?myArgument=12"));
这应该起作用:

$this->redirect(array('controller' => 'tools', 'action' => 'index', 'myArgument' => 12));
看看

:


Cake确实支持使用问号的查询参数,如下所示:

$this->redirect(array(
    'controller' => 'tools', 'action' => 'index', '?' => array(
        'myArgument' => 12
    )
));

但最好是像des说的那样:

$this->redirect(array(
    'controller' => 'tools', 'action' => 'index', 'myArgument' => 12
));

使用此选项重定向:

$this->redirect(array('controller' => 'tools', 'action' => 'index', 'myArgument' => 12));
将分隔符从“:”更改为“=”:


))

好的,这个解决方案将创建这个:“tools/index/myArgument:12”,但我需要这个:“tools/index/?myArgument=12”为什么?您可以使用
$this->params['named']
访问该参数。根据传递额外参数的方式,取决于输出的URL@trante我编辑了我的答案,以向您展示如何访问此参数。我认为没有理由将
CakePHP
路由与经典查询字符串混合使用。有什么具体的原因吗@Ross评论不错,但问题是关于
CakePHP2
;)@des,因为我不想为一个案例更改太多的路由代码:):)@trante simple您可以使用吗<代码>$this->重定向(数组('controller'=>'tools'、'action'=>'index'、'?'=>数组('variableName'=>'variableValue'))然后在操作索引中,您可以使用
$variableValue=$this->request->query('variableName')如Jleagle所示,可以使用数组概念创建标准RFC3986查询字符串,但这通常不是一个好主意。您不想使用Cake的友好URL路由有什么特别的原因吗?没错,我不知道可以使用
?“
来实现这一点。