views:

1819

answers:

5

how can i redirect to another action passing 2 or more parameters? this code:

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

results in URL:

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

Is there a specific reason why you have to use the class redirect method instead of simply header('Location: blahblah'); ?

code_burgar
it's the symfony way of doing this
Jochen Hilgers
Does the symfony way of doing it have any aditional benefits over the vanilla way?
code_burgar
it's just the symfony way, and i'm trying to follow it)
kipelovets
+1  A: 

I think this is no normal symfony behavior. Have you defined some routing rules?

Have you also tried this:

$this->redirect('module/action?'.http_build_query($paramsArray));
Jochen Hilgers
no, that doesn't help
kipelovets
A: 

Strange thing. Does

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

work for you?

develop7
yes, that also work. thanks, but xarch's solution is prettier =)
kipelovets
+1  A: 

Well, that's normal, "redirect" redirect to an absolute URL. You can do that:

$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
xarch
that helped. except for it generates url like "http://.../input/new/year/2009/month/10"
kipelovets
If you have a route defined, you can replace 'default' by its name, and change the second parameter with the routes's parameters, if needed.
xarch
A: 

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

Mohammad
this undermine the internal routing system of symfony
Jochen Hilgers
it actually doesn't. symfony's intelligent internal routing engine is exactly why this redirect works! but thanks for the down vote ;)
Mohammad
when you do it this way you have to change all links/redirects when adjusting the according routing rule
Jochen Hilgers