Responders
Last updated
Last updated
Responders respond data: transform data to a Symfony response, return a success in a CLI operation.
When your operation is an instance of Sylius\Component\Resource\Metadata\HttpOperation
two responders are configured by default.
The responder will automatically choose the responder depending on the request format:
html
Sylius\Component\Resource\Symfony\Request\State\TwigResponder
json
Sylius\Component\Resource\Symfony\Request\State\ApiResponder
xml
Sylius\Component\Resource\Doctrine\Common\State\ApiResponder
The Twig responder is used to render data into a Symfony response. It's used for HTML responses.
The variables that are passed to the Twig templates depends on the operation (See chapter).
Some variables are already available on your operations, but you can add more variables easily.
As an example, we add a foo
variable to the Twig template with bar
as value.
Use it on your operation.
The API responder is used to render serialized data into a Symfony response. It's used for JSON/XML responses.