Symfony路由注释

时间:2018-05-21 11:27:22

标签: php symfony

我正在尝试在控制器上添加新路由,但在使用电子邮件参数时遇到了问题:

use Symfony\Component\Routing\Annotation\Route;

   /**
     * @Route("/foo/{email}", methods="GET")
     *
     * @param string $email
     *
     * @return JsonResponse
     */
    public function fooAction(string $email) { 
        return JsonResponse::create('OK!');
    }

似乎Symfony路由不允许.

  • 127.0.0.1 [200]:/ foo / test @ testcom
  • 127.0.0.1 [404]:/ foo/test@test.com

我是否需要添加一些东西以使其有效?

4 个答案:

答案 0 :(得分:1)

好吧,因为我在开发环境中,并且我使用

启动服务器
  

php -S 127.0.0.1:8000 -t public

使用symfony / web-server-bundle工作

答案 1 :(得分:0)

尝试使用'/'

结束路线

@Route(“/ foo / {email} /”,methods =“GET”)

答案 2 :(得分:0)

您需要首先对电子邮件地址进行URL编码吗?

答案 3 :(得分:0)

你应该用正则表达式解决这个问题,尝试一些like this answer

希望它有所帮助!

相关问题