FOSRestBundle adds 'S' in get URL
fosuserbundle, php, symfony
Solution
after digging in the code:
- https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Routing/Loader/Reader/RestActionReader.php
Here it is:
private function generateUrlParts(array $resources, array $arguments)
{
$urlParts = array();
foreach ($resources as $i => $resource) {
// if we already added all parent routes paths to URL & we have
// prefix - add it
if (!empty($this->routePrefix) && $i === count($this->parents)) {
$urlParts[] = $this->routePrefix;
}
// if we have argument for current resource, then it's object.
// otherwise - it's collection
if (isset($arguments[$i])) {
if (null !== $resource) {
$urlParts[] =
strtolower(Pluralization::pluralize($resource))
.'/{'.$arguments[$i]->getName().'}';
} else {
$urlParts[] = '{'.$arguments[$i]->getName().'}';
}
} elseif (null !== $resource) {
$urlParts[] = strtolower($resource);
}
}
return $urlParts;
}
I've opened an issue:
- https://github.com/FriendsOfSymfony/FOSRestBundle/issues/247
in hopes that this would become optional
Problem
// MySomethingController.php ``` // look no s public function getSomethingAction($args) { ... } ``` // routing.yml ``` my_something: type: rest resource: Blah\Bundle\BlahBundle\Controller\MySomethingController ``` running: ``` php app/console router:debug ``` Output: ``` [router] Current routes Name Method Pattern get_something GET /somethings/{args}.{_format} ``` Why is the route 'somethings' ( plural with an 's' ) instead of 'something'? is this a setting I have somewhere? or is this expected?