CakePHP在Controller :: redirect中传递参数 [英] CakePHP passing arguments in Controller::redirect

查看:115
本文介绍了CakePHP在Controller :: redirect中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在控制器动作中进行重定向我使用这个:

  $ this-& >'tools','action'=>'index')); 

或此

 code> $ this-> redirect('/ tools / index'); 

当我使用重定向传递数据时,我使用这个:

  $ this-> redirect('tools / index /?myArgument = 12'); 

但是我找不到如何传递myargument的this-redirect-array 。

我不想使用这个,因为一些路由问题:

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

我需要这样的:

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


解决方案

Cake确实支持使用问号的查询参数,像这样:

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


http://book.cakephp.org/2.0/en/development/routing.html#reverse-routing



但是最好只是做,像des说:

  $ this-> redirect b'controller'=>'tools','action'=>'index','myArgument'=> 12 


In controller actions to make redirect I use this:

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

or this

$this->redirect('/tools/index');

And when I pass data with redirect I use this:

$this->redirect('tools/index/?myArgument=12');

But I couldn't find how to pass "myargument" by "this-redirect-array" notation.
I don't want to use this because some routing issues:

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

I need something like this:

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

解决方案

Cake does indeed support query arguments using the question mark, like this:

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

http://book.cakephp.org/2.0/en/development/routing.html#reverse-routing

But it would be better to just do, like des said:

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

这篇关于CakePHP在Controller :: redirect中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆