2012-04-25 22 views
1

爲什麼我不能使用Symfony 1.4中的兩個參數進行重定向?用兩個參數重定向?

$this->redirect('news/edit?id='.$news->getId() . '&test='.$news->getTest()); 

這重定向我http://mysite.com/news/edit/id/3,而不是到:

http://mysite.com/news/edit/id/3/test/4

如何使兩個參數重定向?

+2

它適用於我這種方式:S也許這與你的路由系統有關 – 2012-04-25 13:18:41

回答

3

您的解決方案應該可以正常工作。

但請檢查$news->getTest()是否爲空,並檢查您是否沒有導致問題的路由。

或者,你可以試試這個:

$this->getRequest()->setParameter('id', $news->getId()); 
$this->getRequest()->setParameter('test', $news->getTest()); 
$this->forward('news', 'edit'); 
1

重定向expecst一個網址,你可以建立這個網址的URL輔助方法,如

url_for2($routeName, $params = array()); 

其中params爲關聯數組。