gpt4 book ai didi

php - FOSRestBundle 在获取 URL 中添加 'S'

转载 作者:可可西里 更新时间:2023-11-01 14:04:23 26 4
gpt4 key购买 nike

//MySomethingController.php

// look no s
public function getSomethingAction($args)
{
...
}

//路由.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}

为什么路由是“somethings”(带“s”的复数)而不是“something”?

这是我在某处设置的吗?或者这是预期的?

最佳答案

深入研究代码后:

这里是:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com