kipelovets
kipelovets

Reputation: 1214

symfony redirect with 2 parameters

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

Upvotes: 39

Views: 111066

Answers (6)

forsberg
forsberg

Reputation: 1913

In the currently supported Symfony versions (2.7+) it's even easier (plus, you can optionally add also the status code at the end):

return $this->redirectToRoute(
    'default',
    array('year' => $year, 'month' => $month),
    Response::HTTP_MOVED_PERMANENTLY // = 301
);

Upvotes: 11

Mohammad
Mohammad

Reputation: 732

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

Upvotes: -4

Guillermo Gutiérrez
Guillermo Gutiérrez

Reputation: 17799

You can also use redirect, specifying the route name and the parameter array:

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

(Tested on Symfony 1.4)

Upvotes: 5

xarch
xarch

Reputation: 732

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)));

Upvotes: 58

Andrei Dziahel
Andrei Dziahel

Reputation: 969

Strange thing. Does

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

work for you?

Upvotes: 1

jochil
jochil

Reputation: 1074

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));

Upvotes: 3

Related Questions