[英]Empty route path for different methods in symfony
I'm developing an API using Symfony and FOSRestBundle, and want to use the following routes: 我正在使用Symfony和FOSRestBundle开发API,并希望使用以下路由:
app/config/routing.yml app / config / routing.yml
page:
prefix: /page
resource: "@PageBundle/Resources/config/routing.yml"
PageBundle/Resources/Config/routing.yml PageBundle /资源/Config/routing.yml
page_get:
path: /{id}
methods: GET
defaults:
_controller: PageBundle:Page:get
id: null
page_post:
path: /
methods: POST
defaults:
_controller: PageBundle:Page:post
The same for PUT and DELETE... PUT和DELETE相同...
When I call GET for /page works fine, but when call POST for /page I get the following error: 当我为/ page调用GET时,工作正常,但是当为/ page调用POST时,出现以下错误:
No route found for "POST /page": Method Not Allowed (Allow: GET, HEAD)
I need to call /page/ instead of /page , then it works... 我需要调用/ page /而不是/ page ,然后它可以工作...
What can I do to use the same empty path for differents methods? 如何为不同方法使用相同的空路径?
Sorry for my bad english. 对不起,我的英语不好。
What you need to do is remove prefix
from app/config/routing.yml 您需要做的是从app / config / routing.yml中删除
prefix
page:
resource: "@PageBundle/Resources/config/routing.yml"
And add it to path in PageBundle/Resources/Config/routing.yml 并将其添加到PageBundle / Resources / Config / routing.yml中的路径
moodul_page_get:
path: /page/{id}
methods: GET
defaults:
_controller: MoodulPageBundle:Page:get
id: null
moodul_page_post:
path: /page
methods: POST
defaults:
_controller: MoodulPageBundle:Page:post
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.