douxitao8170 2017-04-03 06:18
浏览 29
已采纳

FOS REST Bundle:有趣的东西有“人”资源

I'm using FOS Rest bundle to create a REST resource for a "persons" resource, basically the urls are meant to be:

  • List: GET /api/persons
  • Add: POST /api/persons
  • Get single person: GET /api/persons/{id}
  • Modify: PUT /api/persons/{id}
  • Delete: DELETE /api/persons/{id}

So I defined my methods in the controllers as follows:

public function cgetPersonsAction() # List
public function cgetPersonAction(...) # Get single
public function cdeletePersonAction(...) # Delete
#etc...

And here comes the funny part, instead of /api/persons for get single, put, post and delete FOS Rest bundle calculates the plural of person into people instead of persons and the urls ended up being:

  • List: GET /api/persons
  • Add: POST /api/people
  • Get single person: GET /api/people/{id}
  • Modify: PUT /api/people/{id}
  • Delete: DELETE /api/people/{id}

I searched the code looking for maybe some people/person in the bundle but I found nothing, so I guess it must be related with some php plural function.

Do you know if there's any way to force the url to remain being "person"? I think people doesn't make too much sense here

  • 写回答

1条回答 默认 最新

  • dongsonglian7303 2017-04-03 07:08
    关注

    You can force the url by using:

    FOS\RestBundle\Controller\Annotations\Get; ...\Post; ,...
    

    For GET url it would be:

    @Get("api/whatever/{id}")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部