symfony redirect con 2 parámetros


¿Cómo puedo redirigir a otra acción pasando 2 o más parámetros? este código:

$this->redirect('input/new?year=' . $year . '&month=' . $month);

Resultados en URL:

http://.../input?year=2009&month=9

Author: kipelovets, 2009-09-30

6 answers

Bueno, eso es normal, "redireccionar" redireccionar a una URL absoluta. Puedes hacer eso:

$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
 53
Author: xarch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-30 17:48:47

También puede usar redirect, especificando el nombre de la ruta y el array de parámetros:

$this->redirect('route_name', array('year' => $year, 'month' => $month));

(Probado en Symfony 1.4)

 4
Author: Guillermo Gutiérrez,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-20 18:30:19

Creo que este no es un comportamiento normal de symfony. ¿Ha definido algunas reglas de enrutamiento?

¿También has probado esto:

$this->redirect('module/action?'.http_build_query($paramsArray));
 3
Author: jochil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-30 09:24:37

En las versiones compatibles de Symfony (2.7+) es aún más fácil :

return $this->redirectToRoute('default', array('year' => $year, 'month' => $month));
 3
Author: forsberg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-29 15:41:39

Cosa Extraña. Does

$this->redirect('@default?module=input&action=new&year=' . $year . '&month=' . $month);

Trabajar para usted?

 1
Author: develop7,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-09-30 12:40:48
$this->redirect('input/new/year/' . $year . '/month/' . $month);
 -3
Author: Mohammad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-20 18:30:41