I'm new to symfony and I just started to build a pilot project for learning purposes. Using symfony 3 and having an app I would like to build with FOSRest a JSON based API and another separate bundler should provide the Backend on user authentication for data manipulation. The problem if I add the following in my
app/config_dev.yml
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
I get No engine is able to work with the template ""
.
How do I manage to have separate response per separate bundles?
You can't configure a 3rd party bundle differently in 2 of your bundles.
But, you can deal with route patterns in the format_listener
option:
fos_rest:
# ...
format_listener:
rules:
- { path: '^/json', priorities: ['json'], fallback_format: json, prefer_extension: false }
- { path: '^/html', priorities: ['html'], fallback_format: html, prefer_extension: false }
Like this, the routes matching with ^/json
will render JSON
and /html
will render HTML
by default.
For more, look at the listener configuration.