We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



98.9k

Hi Phillpp, check this example out, https://docs.phalcon.io/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!