Symfony events: kernel.view reference
20 November 2022 (Updated 20 November 2022)
On this page
When is it dispatched?
Dispatched after the controller has been executed but only if the controller doesn’t return a Response
object.
Use cases
- Transform the returned value (e.g., an HTML string) into a
Response
object needed by Symfony.
Example
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ViewEvent;
public function onKernelView(ViewEvent $event)
{
$value = $event->getControllerResult();
$response = new Response();
// ... somehow customize the Response from the return value
$event->setResponse($response);
}
List event listeners
php bin/console debug:event-dispatcher kernel.view
Sources
- Built-in Symfony Events – Symfony docs
- The
kernel.view
Event - Symfony events: kernel.request reference
- Symfony events: kernel.controller reference
- Symfony events: kernel.controller_arguments reference
- Symfony events: kernel.view reference
- Symfony events: kernel.response reference
- Symfony events: kernel.finish_request reference
- Symfony events: kernel.terminate reference
- Symfony events: kernel.exception reference
Tagged:
Symfony
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment