Specifically, I'm trying to use the FlashMessenger plugin form within my Module.php file.
Right now the method inside my Application/Module.php
file looks like this:
public function checkAcl(MvcEvent $e) {
// code to determine route and role ...
if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
$flashMessenger = $e->getController()->plugin('flashMessenger');
$flashMessenger->addMessage('You must be logged in');
// code to redirect to login page ...
}
}
But that is not working because $e->getController() is returning a string, not the controller object. Any help accessing either the controller or the plugin directly is appreciated.
You can use the ControllerPluginManager to get an instance of the flashMessenger from any event handler in your Module.php like so:
public function myEventHandler(MvcEvent $e) {
$sm = $e->getApplication()->getServiceManager();
$flash = $sm->get('ControllerPluginManager')->get('flashMessenger');
$flash->addErrorMessage('test');
// ...
}
Obviously you can do this for any controller plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With