FOSRestBundle doesn't work in Symfony 4.1

后端 未结 4 2050
无人共我
无人共我 2021-02-20 12:52

I have problem with returning views with FOSRestBundle working under Symfony 4.1 Project.

This is code from my controller:

class NewsController extends          


        
4条回答
  •  误落风尘
    2021-02-20 13:15

    Do you send the Accept: application/json in your request?

    If not, you do not necessarily need twig, but you need to remove html from the format configuration in the bundle config:

    fos_rest:
        format_listener:
            rules:
                - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ json ] }
    

    The default is to have html in the priorities, and that requires twig.

提交回复
热议问题