Search code examples
zend-frameworkzend-framework2

Zend framework 2 toroute pass variable to next controller


After a succes form i want to redirect to another controller, i do that with toRoute. Below there is an example

return $this->redirect()->toRoute('plaatsenrubriek',array('controller'=>'AdvertentieController', 'action'=>'plaatsenrubriek'));

Is there a way to insert a variable in the toRoute to pass to the next controller?


Solution

  • The only way to pass a variable during a redirect would be to add a query parameter to the target route.

    $bar = 'bar';
    
    $this->redirect()->toRoute('myRoute', array(), array(
        'query' => array(
            'foo' => $bar,
        )
    ));
    

    Which would result in /myRoute?foo=bar