A
A
Alexander2021-08-12 15:13:38
symfony
Alexander, 2021-08-12 15:13:38

How to use the kernel.controller event?

In general, I need to change the controller according to a certain logic, I found the kernel.controller event in the docks and hung a method on it:

public function onKernelController(ControllerEvent $event)
{
       $controllerName = 'App\Controller\ToController::index';

       // вот тут по логике $event->setController();
}


But I can't figure out what should I put in setController if I have a path to the controller? Didn't find anything in the documentation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2021-08-12
@sl0

You need to get the controller through the ControllerResolverInterface resolver and already pass it to setController.
Only there is some tricky way to get it through the resolver, as far as I remember, it’s not just the path that needs to be passed there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question