FOS\RestBundle, "Unrecognized options" on Symfony2
Asked Answered
H

2

6

I've a problem with Symfony2 creating Rest API and using FOS\RestBundle

When I try to generate a database or an entity… Whatever I try to generate, an error occurs.

root@symfonyRest:/var/www/Symfony# php5 app/console doctrine:database:create



  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]  
  Unrecognized options "prefer_extension" under "fos_rest.format_listener"  

The problem seems to be in the config.yml

config.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

framework:
    #esi:             ~
    #translator:      { fallback: %locale% }
    secret:          %secret%
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
[…]

sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }

fos_rest:
    format_listener:
        prefer_extension:       false
    view:
        view_response_listener: true

EDIT :

new config.yml with format_listener.rules

fos_rest:
    view:
        view_response_listener:  true
    format_listener:
        rules:
            prefer_extension:     false

But I've an error too

[Symfony\Component\Config\Definition\Exception\InvalidTypeException]         
  Invalid type for path "fos_rest.format_listener.rules.prefer_extension". Ex  
  pected array, but got boolean

Anybody have a solution to my problem ? Thanks !

Hafer answered 19/11, 2013 at 12:18 Comment(0)
H
5

I found the mistake !

The correct configuration it's :

fos_rest:
    format_listener:
        rules:
            - prefer_extension: false

Don't forget the "-"

EDIT: Typo corrected

Hafer answered 20/11, 2013 at 20:52 Comment(1)
I am getting the below error, with the above config.... [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] There is no extension able to load the configuration for "fost_rest" (in /v ar/www/l/app/config/config.yml). Looked for namespace "fost_rest", fou nd "framework", "security", "twig", "monolog"Tupelo
P
10

Have a look at the bundle's configuration reference:

You have not added the prefer_extension under format_listener.rules but as a direct child of format_listener.

The correct configuration would be:

fos_rest:
    format_listener:
        rules:
            - prefer_extension: false
Prunella answered 19/11, 2013 at 12:29 Comment(0)
H
5

I found the mistake !

The correct configuration it's :

fos_rest:
    format_listener:
        rules:
            - prefer_extension: false

Don't forget the "-"

EDIT: Typo corrected

Hafer answered 20/11, 2013 at 20:52 Comment(1)
I am getting the below error, with the above config.... [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] There is no extension able to load the configuration for "fost_rest" (in /v ar/www/l/app/config/config.yml). Looked for namespace "fost_rest", fou nd "framework", "security", "twig", "monolog"Tupelo

© 2022 - 2024 — McMap. All rights reserved.