//MySomethingController.php
// look no s
public function getSomethingAction($args)
{
...
}
//routing.yml
my_something:
type: rest
resource: Blah\Bundle\BlahBundle\Controller\MySomethingController
运行:
php app/console router:debug
输出:
[router] Current routes
Name Method Pattern
get_something GET /somethings/{args}.{_format}
为什么路由是“某物”(带有“s”的复数)而不是“某物”?
这是我在某处的设置吗?还是这是预期的?
最佳答案
探究代码后:
这里是:
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;
}
我已经开了一个问题:
希望这将成为可选
关于php - FOSRestBundle在获取URL中添加 'S',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10922184/