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

标签 php symfony fosrestbundle

谁能告诉我 FOSRestBundle 的引用配置,它只允许 json + xml,如果没有设置“Accepted”或“Content-Type”,将默认为 json。

我的目标是放弃模板 html 支持和所有其他不必要的格式(在我的例子中)。

提前致谢!

最佳答案

明白了。

# 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 }
# ...

关于php - FOSRestBundle - 仅允许 json + xml,如果没有其他请求则默认为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929152/

相关文章:

php - Laravel:从数据库填充表单下拉列表

rest - FOS 休息包 : unable to find template

forms - FOSRestBundle 将 json 数据发布到表单不起作用

php - 为什么 float 的打印方式如此不同?

php - YOUTUBE API : Retrieve video keywords

php - 使用连接比较sql查询中的两个表

symfony - 如何在 Symfony2 中优化 DQL 查询?

php - fatal error : composer. 锁定是为 PHP 版本 7.4 或更高版本创建的,但当前 PHP 版本是 7.3.11

php - Swift_Mailer Symfony 3 添加事件监听发送事件

php - 不允许使用父属性