FOSRestBundle 捕获所有路由

FOSRestBundle Catching All Routes

我正在尝试将 FOSRestBundle 集成到我的应用程序中。

我只想在路由匹配时使用它 ^/api

我真的不知道如何使用这个包,而且我认为文档非常糟糕。 (无意冒犯)。

fos_rest:
    format_listener:
        enabled: true
        rules:
            - { path: '^/api', priorities: ['json', 'xml'], fallback_format: 'html' }

当我从浏览器请求任何路由时,出现此错误:

No matching accepted Response format could be determined

我只想匹配以^/api开头的路由。

有什么想法吗?

您需要使用 zones 功能:

# app/config/config.yml
fos_rest:
    zone:
        - { path: ^/api/* }

在官方文档中阅读更多相关信息:http://symfony.com/doc/master/bundles/FOSRestBundle/3-listener-support.html#zone-listener