>From my perspective this is the most common approach we take to handle this >scenario. I would say you should prob define your callback method as a class >method defined on the Module class, but that's purely subjective otherwise I >see nothing wrong with this approach.
Another main point is you should always try to write loosely coupled and dependant free code, this way it doesn't matter which framework you use. A framework is just a framework - tools to help you. Its much more important to understand software engineering as a whole, rather than learn a framework. Best, Daniel -----Original Message----- From: "David Mintz" <[email protected]> Sent: 16/07/2015 23:06 To: "lists lists" <[email protected]> Subject: [fw-general] authentication and the EventManager: best place to testif user is logged in 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/
