FOSRestBundle adds an "S" to the URL

//MySomethingController.php

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

//routing.yml

my_something:
    type:     rest
    resource: Blah\Bundle\BlahBundle\Controller\MySomethingController

works:

php app/console router:debug

Conclusion:

[router] Current routes
Name                Method     Pattern
get_something       GET        /somethings/{args}.{_format}

Why is the route "somethings" (plural with "s") instead of "something"?

Is this a parameter that I have somewhere? or is it expected?

+5
source share
2 answers

after digging in code:

There he 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 object.
        // otherwise - it 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 discovered the problem:

in the hope that this will become optional

+3
source

This is a response to a ticket-based update opened by @phillpafford.

Ismith77 , , , :

, , , № 52. , REST, GET "subdir" .

, "" REST, /member/ {id}.{_format} , /member {.format}.

, , REST .

PS: , "", , ...

+3
source

All Articles