gpt4 book ai didi

php - 如何使用 Symfony 将参数传递给 Controller ​​?

转载 作者:行者123 更新时间:2023-12-02 07:06:01 24 4
gpt4 key购买 nike

我像这样将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com