Fosrestbundle: [S4 ]View Response Listener - twig error

Created on 17 Jan 2018  路  4Comments  路  Source: FriendsOfSymfony/FOSRestBundle

Hi. I am using S4. When I try to use the @View annotation, receives an error : There are no registered paths for namespace "FOSRest". What am I doing wrong ?

`

/**
 *@Rest\Get(
 *     "/busy-times",
 *     name="app.api.busytime.get_busy_times"
 * )
 * @Rest\View()
 */
public function getBusyTimes(): array
{
    /** @var User $user */
    $user = $this->getUser();
    $doctrine = $this->getDoctrine();

    $busyTimes = $doctrine->getRepository(BusyTime::class)->findAll();

    if (false == $user->isSuperAdmin()) {
        $decoratedBusyTimes = [];
        /** @var BusyTime $busyTime */
        foreach ($busyTimes as $busyTime) {
            $decoratedBusyTimes[] = new BusyTimeDecorator($busyTime, $this->translator);
        }
        $busyTimes = $decoratedBusyTimes;
    }

    return $busyTimes;
}

`

`
fos_rest:
param_fetcher_listener: true
serializer:
serialize_null: false
view:
view_response_listener: 'force'
body_converter:
enabled: true
validate: true
validation_errors_argument: validationErrors

`

Most helpful comment

I had the same issue on SF 4+ and fixed it by configuring the namespaced path in Twig;

twig:
    paths:
        "%kernel.project_dir%/templates": FOSRest

All 4 comments

How did you solve this, i'm getting the same error in my unit tests.

I had the same, solved it when I added the following configuration under fos_rest :

    format_listener:
        rules:
            prefer_extension: false
            fallback_format: json

I had the same issue on SF 4+ and fixed it by configuring the namespaced path in Twig;

twig:
    paths:
        "%kernel.project_dir%/templates": FOSRest

If you are encountering the same error: do not open URL from a web brower.
Use postman or any other REST client.

Was this page helpful?
0 / 5 - 0 ratings