FOS rest bundle: unable to find template

放肆的年华 提交于 2019-11-30 12:31:45

I managed to resolve this issue by setting the listener explicitly to false:

fos_rest:
    format_listener: false

EDIT

This also works:

fos_rest:
    format_listener:
        prefer_extension: false
        default_priorities:
            - json

For FOSRestBundle version 2.0 the config should be

fos_rest:
    format_listener:
        rules:
            prefer_extension: false
            fallback_format: json

Annotate your controller action with @View to resolve this issue.

use FOS\RestBundle\View\View;

Have a look at the documentation chapter View Response listener.


If you don't want to annotate every action - you can set the @View annotation for a complete class using my pull request here.

Add this to your composer.json to use the PR.

"require": {
    "friendsofsymfony/rest-bundle": "dev-dev-view-addition as 0.12.0", 

// ...

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/nifr/FOSRestBundle"
    },

(For reference) If One is testing with a rest client or manually be sure to set the header in your request: Accept:application/json

Because fosRestBundle tries to determine the proper response type from the headers in the request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!