Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate custom routes for some actions with FOSRESTBundle?

I actually use automatic route generation for my api Rest, using the FOSRESTBundle, also I use NelmioApiDocBundle to generate the api doc.

To generate routes for the api this I have in my routing.yml

users:
    type:     rest
    resource: Project\RESTBundle\Controller\UsersController

But for some actions I want to set my custom routing... If I try to add another route rule for an action it simply ignore it and generate the automatic route.

like image 433
Fernando P. G. Avatar asked Feb 17 '23 16:02

Fernando P. G.


1 Answers

You have to declare the route with the same name right after the configuration you set. For example, the following works.

users:
    type:     rest
    resource: Project\RESTBundle\Controller\UsersController

get_users:
    pattern:  /api/users/customUri.{_format}
    defaults: { _controller: ProjectRESTBundle:Users:indexAction, _format: json }
like image 122
P. R. Ribeiro Avatar answered May 02 '23 17:05

P. R. Ribeiro