我现有的应用程序需要额外的RESTful端点。
我已使用以下配置添加了FOSRestBundle。
fos_rest:
param_fetcher_listener: true
view:
mime_types:
json: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1', 'application/json;version=1.2']
view_response_listener: 'force'
formats:
xml: false
json: true
templating_formats:
html: false
format_listener:
rules:
- priorities: [json, xml]
- fallback_format: json
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
allowed_methods_listener: true
access_denied_listener:
json: true
body_listener: true
routing_loader:
default_format: json
include_format: false
REST请求很好,但基本路由现在不起作用
出现以下错误
This page contains the following errors:
error on line 11 at column 92: EntityRef: expecting ';'
Below is a rendering of the page up to the first error.
基本上我只想将基本路由与休息结合起来
答案 0 :(得分:1)
您可以通过禁用特定html路由的格式侦听器来解决此问题(请参阅http://symfony.com/doc/current/bundles/FOSRestBundle/format_listener.html#disabling-the-format-listener-via-rules)
因此,请在config.yml中为格式侦听器添加规则,如下所示:
format_listener:
rules:
- { path: '^/my-html-routes', stop: true }
- { path: '^/api', priorities: ['json', 'xml'], fallback_format: json }