sajad torkamani

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.


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


List event listeners

php bin/console debug:event-dispatcher kernel.view


Tagged: Symfony