Maybe you want to roll your own as a practice exercise, but if not, I suggest you take a good look at BjyAuthorize. It's basically a module implementation of Acl.
Jeremiah > On Jul 16, 2015, at 3:06 PM, David Mintz <[email protected]> wrote: > > I am just getting started with ZF2 (now that people are talking about ZF3 > (-: ) and wondering what the recommended practice is in the following case. > I have a module where I want to require the user be logged in to access any > controller/action under this module, otherwise redirect to a login page (in > another module). > > I have experimented with attaching a listener to the 'dispatch' event in my > Module.php's onBootstrap method. Something like : > > public function onBootstrap(MvcEvent $e) > { > /* .......*/ > > $eventManager->attach('dispatch', function() use ($e, > $authenticated) { > > if (! $authenticated) { > $target = $e->getTarget(); > if ($target instanceof > \Zend\Mvc\Controller\AbstractActionController) { > if ( 0 === strpos(get_class($target),'MyModule')) { > $target->redirect()->toRoute('login'); > } > } > } > > Is this basically the right approach? Or is there a better way to go at > this? > > Thanks. > > -- > David Mintz > http://davidmintz.org/ > Human needs before private profit: > http://socialequality.com/ -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
