2012-08-07 75 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(); 
相关问题