douxitao8170 2017-04-03 14: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 15:08
    关注

    You can force the url by using:

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

    For GET url it would be:

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

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏