I have problem with returning views with FOSRestBundle working under Symfony 4.1 Project.
This is code from my controller:
class NewsController extends
You must enable the SensioFrameworkExtraBundle view annotations
sensio_framework_extra:
view: { annotations: false }
Templating component integration is deprecated in Symfony 4.3. So templating section must be removed (or commented) from config/packages/framework.yaml
framework:
# templating: { engines: ['twig'] }
To define Twig as templating service in ViewHandler add lines below to config/services.yaml
fos_rest.templating: alias: twig
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
.
Add line to config/packages/framework.yaml
framework:
templating: { engines: ['twig'] }
it will solve
An instance of Symfony\Bundle\FrameworkBundle\Templating\EngineInterface >must be injected in FOS\RestBundle\View\ViewHandler to render templates.