Created
December 2, 2012 22:09
-
-
Save rlandas/4191276 to your computer and use it in GitHub Desktop.
ZF2: Assigning variables to the controller using events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see http://samsonasik.wordpress.com/ | |
public function onBootstrap(MvcEvent $e) | |
{ | |
$sharedEvents = $e->getApplication()->getEventManager()->getSharedManager(); | |
$sm = $e->getApplication()->getServiceManager(); | |
$sharedEvents->attach('Zend\Mvc\Controller\AbstractActionController','dispatch', | |
function($e) use ($sm) { | |
$controller = $e->getTarget(); | |
$controller->em = $sm->get('em'); | |
}, 100 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment