【问题标题】:How to pass argument to controller with Symfony?如何使用 Symfony 将参数传递给控制器​​?
【发布时间】:2012-08-07 08:21:54
【问题描述】:

我像这样将 var argurmrnt 传递给控制器​​

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\Controller\UserController::ProfileAction()”需要 为“$var”参数提供一个值(因为没有 默认值或因为在此之后有一个非可选参数 一)。

【问题讨论】:

    标签: php symfony controller


    【解决方案1】:

    根据docs,您忘记在路线中添加占位符

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2022-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多