Using the active controller inside a beforeExecuteRoute event

Hey there,

I noticed that in an beforeExecuteRoute event, the controller is already initialized (i.e. the method initialize() was loaded and the controller exists somewhere). How can I access it from within an event handler if that handler is a Phalcon\Mvc\User\Plugin?

Thanks in advance!

Best, Philipp



83.4k

Hi Phillpp, check this example out, http://docs.phalconphp.com/en/latest/reference/annotations.html#practical-usage

It uses the current controller in a beforeExecuteRoute event

Hey @phalcon,

thanks for the link, I already got that far ;). But what I couldn't figure out is how to access the controller object of the currently active controller from inside that plugin.

e.g. $this->controller->element from MyController { $element = 123; }

arr

$dispatcher->getActiveController()

Thanks!