Open abitofBaileys opened 6 years ago
Solution 2: Define the singular route(s) in the controller method:
/**
* Show a single car-item identified by id
*
* @param int $id
*
* @Get("car/{id}")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
The @Get("car/{id}")
does the magic here. Do the same for PUT, DELETE and POST:
Method | Route |
---|---|
postCarAction | @Post("car") |
putCarAction | @Put("car/{id}") |
deleteCarAction | @Delete("car/{id}") |
Also include the required namespaces:
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\Put;
use FOS\RestBundle\Controller\Annotations\Delete;
Problem
In this ExampleNewsBundle a potential issue doesn't occur due to the nature of "news" being plural by default. Should someone try to recreate the steps to create his own bundle based on the pull requests or the blog posts, they may run into
Route not found
problems regarding the routing as FOSRestBundle defaults routes to plural.Example
Creating a Bundle working with singular
CarBundle
results in different routes if you work with singular terms throughout the tutorial, ultimately ending up with singular and plural routes conflicting.Solution
It is not necessary to change the entire tutorial, but it would be nice to remind the reader to work with plurals from the beginning and refer to this Symfony article to avoid this situation.