FOSRestBundle - 仅允许json + xml,如果没有其他请求则默认为json

n00*_*00b 7 php symfony fosrestbundle

有人可以给我看一个FOSRestBundle的参考配置,它只允许json + xml和willd默认为json,如果没有设置"Accepted"或"Content-Type".

我的目标是删除模板html支持和所有其他不必要的格式(在我的情况下).

提前致谢!

n00*_*00b 13

得到它了.

# app/config/config.yml
# ...
fos_rest:
    routing_loader:
        default_format: json
        include_format: true
    param_fetcher_listener: force
    body_listener: true
    allowed_methods_listener: true
    view:
        view_response_listener: 'force'
        formats:
            json: true
            xml: true
    format_listener:
        rules:
            - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }

sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }
# ...
Run Code Online (Sandbox Code Playgroud)