In Zend Framework 2, how do you use a controller plugin outside the controller -
specifically, i'm trying use flashmessenger plugin form within module.php file.
right method inside application/module.php
file looks this:
public function checkacl(mvcevent $e) { // code determine route , role ... if (!$e->getviewmodel()->acl->isallowed($userrole, $route)) { $flashmessenger = $e->getcontroller()->plugin('flashmessenger'); $flashmessenger->addmessage('you must logged in'); // code redirect login page ... } }
but not working because $e->getcontroller() returning string, not controller object. accessing either controller or plugin directly appreciated.
you can use controllerpluginmanager instance of flashmessenger event handler in module.php so:
public function myeventhandler(mvcevent $e) { $sm = $e->getapplication()->getservicemanager(); $flash = $sm->get('controllerpluginmanager')->get('flashmessenger'); $flash->adderrormessage('test'); // ... }
obviously can controller plugin.
Comments
Post a Comment