删除Symfony2 API URL尾部斜杠

时间:2015-05-22 07:15:36

标签: symfony

我开始使用Symfony2设计一个API,我对路径上的尾部斜杠有问题。

例如,假设我有一个Person实体,在routing.yml文件中以/ person为前缀:

api.persons:
    resource: "@AppBundle/Controller/PersonsController.php"
    type: annotation
    prefix: /persons

在控制器的注释中:

@Route("/", methods="{GET}", name="persons_get"))

Symfony2命令router:debug的结果将为我提供以下网址:/persons/。我想删除这个尾随斜杠。你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我前段时间也遇到过这个问题,在寻找解决方案时我发现了这个问题:https://github.com/symfony/symfony/issues/1972

我同意Fabien(fabpot),因为前缀的使用方式与目录相同,所以您必须设置一个将附加到前缀的字符串,并且使用空路径是无意义的。

如果您不想使用尾部斜杠,请将其定义为:

@Route("/persons", methods="{GET}", name="persons_get")

仅出于合成目的使用前缀。