我像这样将 var argurmrnt 传递给 Controller
return $this->redirect($this->generateUrl('user_profile', array('var' => $profile->getId())));
这是我的 Controller
/**
* @Route("/profile", name="user_profile")
* @Template()
*/
public function ProfileAction($var)
{
$em = $this->getDoctrine()->getEntityManager();
但是我一直报错
Controller "xxxx\Controller\UserController::ProfileAction()" requires that you provide a value for the "$var" argument (because there is no default value or because there is a non optional argument after this one).
最佳答案
根据 docs,您忘记在 route 添加占位符
/**
* @Route("/profile/{var}", name="user_profile")
* @Template()
*/
public function ProfileAction($var)
{
$em = $this->getDoctrine()->getEntityManager();
关于php - 如何使用 Symfony 将参数传递给 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11841886/