0

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:

  1. 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?

  1. 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.
BenMorel
  • 34,448
  • 50
  • 182
  • 322
jinxmanj
  • 1
  • 1

1 Answers1

0

your first approach is fail

because (as you found) there is another module for doing such a thing called BJYAUTHORIZE

it has a config for allowing different type of users access which controller/action/module/route/...

plz review it's documentation for more information and also there is a blog post for How to join ZFCUser and BJY together . http://samminds.com/2013/03/zfcuser-bjyauthorize-and-doctrine-working-together/

Sina Miandashti
  • 2,087
  • 1
  • 26
  • 40
  • Thanks for your answer. I have already realized "join zfcuser and bjy together". The example in the link is just one module in the application. But my problem is I just want to use them in only one module and the other modules will not be affected. – jinxmanj Jul 08 '14 at 08:10
  • u can allow the whole route of your 2nd module to bypass bjyauthorize gaurd – Sina Miandashti Jul 09 '14 at 08:20