2016-07-25 26 views

回答

3

讓我們來看看這個方法的來源:

/** 
* Returns a RedirectResponse to the given route with the given parameters. 
* 
* @param string $route  The name of the route 
* @param array $parameters An array of parameters 
* @param int $status  The status code to use for the Response 
* 
* @return RedirectResponse 
*/ 
protected function redirectToRoute($route, array $parameters = array(), $status = 302) 
{ 
    return $this->redirect($this->generateUrl($route, $parameters), $status); 
} 

正如你所看到的第二個參數是$parameters

所以只需將它們作爲數組作爲第二個參數傳遞即可。所以應該使用這樣的:代碼

$this->redirectToRoute('show_page', array('id' => 123)); 
+0

謝謝@dragoste! –

0

樣品:

// Get URL parameter : 
$urlParam = $request->query->get('url-param') ; 

// Transfer parameter 
$urlParameters[ "url-param" ] = $urlParam ; 
return $this->redirectToRoute("eqt_search", $urlParameters) ; 
0

做陣列的新的工作方式爲好。

return $this->redirectToRoute('routename',[ 
     'param1' => $param1, 
    ]); 

輸出將執行查詢字符串。

routename?param1 = data

相關問題