FosRestBundle和SensioFramewordBundle之间的错误

时间:2019-01-19 19:08:05

标签: php symfony4 fosrestbundle

我安装了两个库FOSRest和Sensio,但是出现以下错误:

You must enable the SensioFrameworkExtraBundle view annotations to use the ViewResponseListener. Did you forget to install and enable the TwigBundle?

虽然我不需要Twig,因为我的API会将所有内容发送回json。

我仍然尝试安装它,但是仍然有问题。

这是Sensio的配置:

sensio_framework_extra:
router:
    annotations: false
view:
    annotations: true
request:
    converters: true

对于FOSREST:

fos_rest:
body_converter:
    enabled: true
serializer:
    serialize_null: true
view:
    formats: { json: true, xml: false, rss: false }
    view_response_listener: true
format_listener:
    rules:
        - { path: '^/', priorities: ['json'], fallback_format: 'json' }

没有什么很重要的。

希望你能帮助我。

谢谢

1 个答案:

答案 0 :(得分:0)

虽然这不是最令人满意的解决方案,但我还是在很沮丧的一个小时后按照消息提示安装了TwigBundle。

composer require symfony/twig-bundle

这应该可以解决您的错误。


我说这不是最令人满意的解决方案,因为就像您一样,我根本不需要Twig模板,因此安装它并不自然。我花了很多时间弄清楚为什么FOSRest需要这个。它是否依赖于某些Twig代码块来运行?我不知道,这只是我发现的最好,最快的解决方法。