Reputation: 822
In ZF1 I used to use a ACL plugin to check if a user is trying to access a non-authorized controller via preDispatch method.
I need to do something similar in ZF2. How do I do that?
Upvotes: 1
Views: 231
Reputation: 8186
In ZF2 hooks such as pre/post dispatch has been replaced with Events . The new MVC uses EventManager to fire MVC events such as dispatch .
In your Module.php add
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH,function(MvcEvent $event){
//dispach code comes here
});
}
Alternativly you can use prebuilt module for this purpose which also integrates with Zfc-User https://github.com/bjyoungblood/BjyAuthorize
Upvotes: 4