I'm developping a website by ZendFramework 2. I have 2 modules: module for administration called Administration(route defined like www.mysite.com/admin/...) et module public site called Application(route defined like www.mysite.com/...) I distinguish the 2 modules by the route.
I don't know how to distinguish the two modules based on route.
To make it clear, I have 2 questions for example:
I use Zfcuser for the login system for the module Administration et in
Administration/Module.php
I added the following code to the purpose that if one user doesn't have identity the layout will change to the login form.namespace Administration; use Zend\Mvc\ModuleRouteListener; use Zend\Mvc\MvcEvent; class Module { public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication ()->getEventManager (); $moduleRouteListener = new ModuleRouteListener (); $moduleRouteListener->attach ( $eventManager ); $eventManager->attach('dispatch', array($this, 'checkLoginChangeLayout')); } public function checkLoginChangeLayout(MvcEvent $e) { if (! $e->getApplication ()->getServiceManager ()->get ( 'zfcuser_auth_service' )->hasIdentity ()) { $controller = $e->getTarget (); $controller->layout ( 'layout/authentication.phtml' ); } } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getAutoloaderConfig() { return array ( 'Zend\Loader\StandardAutoloader' => array ( 'namespaces' => array ( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__ ) ) ); } }
But all the 2 modules are affected by the function checkLoginChangeLayout()
. I want to use the module ZfcUser just in the module Administration but not the module Application.
Can I do something about the Module Manager or Event Manager to solve the problem?
- I've found a 3rd party module called BjyAuthorize which is used for ACL by "guard". When I active the module in
application.config.php
, all my 2 modules are controlled by it. But I just want to use the 3rd party module in the module Administration but not the other modules.