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

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

图片转代码服务由CSDN问答提供 功能建议

我正在使用FOS Rest包为“人员”资源创建REST资源,基本上就是网址 成为:

  • 列表:GET / api / persons
  • 添加:POST / api / persons
  • 获取单身人士:GET / api / persons / {id}
  • 修改:PUT / api / persons / {id}
  • 删除:DELETE / api / persons / {id}


      public function cgetPersonsAction(  )#List 
    public function cgetPersonAction(...)#获取单个
    #etc ... 

    这里有一个有趣的部分,而不是/ api / person for get,put,post和delete FOS Rest包计算人的复数而不是人,而网址最终是:

    • 列表:GET / api /人员
    • 添加:POST / api / people
    • 获取单身人士:GET / api / people / {id}
    • 修改:PUT / api / people / {id} < / li>
    • 删除:DELETE / api / people / {id}

      我搜索了代码,寻找捆绑中的某些人/人 但我什么都没发现,所以我猜它必须与一些php复数函数有关。

      你知道是否有办法强迫网址继续成为“人”? 我认为人们在这里没有多大意义

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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:

    点赞 评论

相关推荐 更多相似问题