Skip to content

Instantly share code, notes, and snippets.

@AydinHassan
Created May 8, 2014 12:50
Show Gist options
  • Save AydinHassan/22bfd186bc215ec70b23 to your computer and use it in GitHub Desktop.
Save AydinHassan/22bfd186bc215ec70b23 to your computer and use it in GitHub Desktop.
Dynamically load ZF2 Module
//Module.php
namespace JhHub;
class Module implements
ConsoleBannerProviderInterface,
ConfigProviderInterface,
AutoloaderProviderInterface
{
/**
* {@inheritDoc}
*/
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sm = $e->getApplication()->getServiceManager();
if($e->getRequest() instanceof HttpRequest) {
// Add ACL information to the Navigation view helper
$authorize = $sm->get('BjyAuthorizeServiceAuthorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
\Zend\View\Helper\Navigation::setDefaultAcl($acl);
\Zend\View\Helper\Navigation::setDefaultRole($role);
}
/** @var \Zend\ModuleManager\ModuleManager **/
$moduleManager = $sm->get('ModuleManager');
/**
* This would be replaced with some
* the result of a Doctrine Query
*/
$moduleManager->loadModule('JhFlexiTime');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment