Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP passing arguments in Controller::redirect

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"));
like image 901
trante Avatar asked Nov 30 '22 05:11

trante


1 Answers

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
));
like image 107
472084 Avatar answered Dec 04 '22 11:12

472084