gpt4 book ai didi

Symfony2 + FOS Rest Bundle - 常规路线

转载 作者:行者123 更新时间:2023-12-04 13:13:10 26 4
gpt4 key购买 nike

我正在开发一个使用 Symfony2 和 fos-restbundle 的应用程序。我想创建一些 API 路由和一些常规路由(正好是 AngularJS 前端的一个)。这是我的 fos_rest 配置(以及来自 sensio 的一些配置行):
sensio_framework_extra:
view: { annotations: false }
router: { annotations: true }
request: { converters: true }
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 }
access_denied_listener:
json: true

如你所见,我有 view_response_listener 启用和 查看注释禁用。我找不到为索引操作(AngularJS 必需)定义“常规”(不是 REST)路由(和 View )的方法。一直报错:

ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException: "No matching accepted Response format could be determined" at C:\wamp\www\CRMProject\vendor\friendsofsymfony\rest-bundle\EventListener\FormatListener.php line 69 

我将不胜感激。

最佳答案

您可以为索引页面添加其他规则(例如):

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

阅读有关格式监听器的文档: http://symfony.com/doc/current/bundles/FOSRestBundle/format_listener.html

关于Symfony2 + FOS Rest Bundle - 常规路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33857378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com