每包 FOSRest。如何配置?
FOSRest per bundle. How to configure?
我是 symfony 的新手,我刚刚开始构建一个用于学习目的的试点项目。使用 symfony 3 并拥有一个应用程序,我想用 FOSRest 构建一个基于 JSON 的 API,另一个单独的捆绑器应该提供用户身份验证后端以进行数据操作。如果我在
中添加以下内容,就会出现问题
app/config_dev.yml
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
我得到 No engine is able to work with the template ""
。
我如何设法对每个单独的捆绑包进行单独的响应?
您不能在 2 个捆绑包中以不同方式配置第 3 方捆绑包。
但是,您可以在 format_listener
选项中处理路由模式:
fos_rest:
# ...
format_listener:
rules:
- { path: '^/json', priorities: ['json'], fallback_format: json, prefer_extension: false }
- { path: '^/html', priorities: ['html'], fallback_format: html, prefer_extension: false }
这样,匹配^/json
的路由默认渲染JSON
,/html
默认渲染HTML
。
我是 symfony 的新手,我刚刚开始构建一个用于学习目的的试点项目。使用 symfony 3 并拥有一个应用程序,我想用 FOSRest 构建一个基于 JSON 的 API,另一个单独的捆绑器应该提供用户身份验证后端以进行数据操作。如果我在
中添加以下内容,就会出现问题app/config_dev.yml
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
我得到 No engine is able to work with the template ""
。
我如何设法对每个单独的捆绑包进行单独的响应?
您不能在 2 个捆绑包中以不同方式配置第 3 方捆绑包。
但是,您可以在 format_listener
选项中处理路由模式:
fos_rest:
# ...
format_listener:
rules:
- { path: '^/json', priorities: ['json'], fallback_format: json, prefer_extension: false }
- { path: '^/html', priorities: ['html'], fallback_format: html, prefer_extension: false }
这样,匹配^/json
的路由默认渲染JSON
,/html
默认渲染HTML
。