Skip to content

Instantly share code, notes, and snippets.

@rlandas
Created December 2, 2012 22:09
Show Gist options
  • Save rlandas/4191276 to your computer and use it in GitHub Desktop.
Save rlandas/4191276 to your computer and use it in GitHub Desktop.
ZF2: Assigning variables to the controller using events
// @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