简体   繁体   中英

FOSRestBundle—create singular route

I am creating a RESTFul application using the FOSRestBundle (2.0) for Symfony3. I have a Controller like so:

class GroupsController extends FOSRestController
{
  public function getGroupAction($id) { … }
  public function getGroupAddAction() { … }
}

running bin/console debug:router gives:

…
get_group            GET      ANY      ajax.localhost.dev    /groups/{id}
get_group_add        GET      ANY      ajax.localhost.dev    /group/add
…

But getting a single Group is the request for a single Item, so the route should be: [GET] /group/{id} , in my opinion.

Am I wrong with that? Should the correct route, to get a single group be plural?

So if my opinion is right, how can I change this single route manually? I have tried:

  /**
   * @NamePrefix("group")
   */
  public function getGroupAction() { … }

But that results in an Error telling me, that I can use that annotation only for the Class, not the method.

Yes it should be plural.

If you want to have singular-routes, you can use this in your controller. You can find it in the Symfony documentation .

/**
 * @RouteResource("User", pluralize=false)
 */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM