2012-08-07 186 views
2

我傳遞VAR argurmrnt到控制器這樣如何通過Symfony將參數傳遞給控制器​​?

return $this->redirect($this->generateUrl('user_profile', array('var' => $profile->getId()))); 

這是我的控制器

/** 


     * @Route("/profile", name="user_profile") 
     * @Template() 
     */ 
     public function ProfileAction($var) 
     { 
      $em = $this->getDoctrine()->getEntityManager(); 

但我不斷收到錯誤

控制器「XXXX \控制器\ UserController中:: ProfileAction ()「需要 ,您提供了」$ var「參數的值(因爲沒有 默認值或者因爲有在此之後的非可選參數 之一)。

回答

8

你忘了佔位符添加到您的路線,根據docs

/** 
    * @Route("/profile/{var}", name="user_profile") 
    * @Template() 
    */ 
    public function ProfileAction($var) 
    { 
     $em = $this->getDoctrine()->getEntityManager();