symfony redirect with 2 parameters

后端 未结 6 998
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 07:07

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

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


        
相关标签:
6条回答
  • 2020-12-08 07:29

    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
    );
    
    0 讨论(0)
  • 2020-12-08 07:40

    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)));
    
    0 讨论(0)
  • 2020-12-08 07:42

    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)

    0 讨论(0)
  • 2020-12-08 07:42

    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));
    
    0 讨论(0)
  • 2020-12-08 07:42

    Strange thing. Does

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

    work for you?

    0 讨论(0)
  • 2020-12-08 07:43
    $this->redirect('input/new/year/' . $year . '/month/' . $month);
    
    0 讨论(0)
提交回复
热议问题