Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.15 KB

controller.md

File metadata and controls

44 lines (32 loc) · 1.15 KB

CONTROLLER

This bundle contains an AbstractController to provide a backward compatibility with Symfony.

The following methods are available:

  • dispatchEvent($eventName, BaseEvent $event)
  • getEventDispatcher()
  • getFormHelper()
  • getLogger()
  • getRouter()
  • getSession()
  • getTranslator()
  • notify($eventName, NotificationInterface $notification)
  • toast($eventName, ToastInterface $toast)

dispatchEvent($eventName, BaseEvent $event)

This method provides the same prototype regardless of Symfony version.

Into a controller with Symfony < 4.3:

    $eventDispatcher = $this->get("event_dispatcher");
    $eventDispatcher->dispatch($eventName, $event);

Into a controller with Symfony 4.3 and more:

    $eventDispatcher = $this->get("event_dispatcher");
    $eventDispatcher->dispatch($event, $eventName);

IMPORTANT NOTICE: The $eventName and $event are permuted.

With a controller inherit from our AbstractController, the usage of dispatchEvent($eventName, $event) works always with the following code:

    $this->dispatchEvent($eventName, $event);