Created
May 8, 2014 12:50
-
-
Save AydinHassan/22bfd186bc215ec70b23 to your computer and use it in GitHub Desktop.
Dynamically load ZF2 Module
This file contains 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
//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