0

I am new in ZendFramework2, need to check identity of user at once. Right now I am checking in every controller action (sample code in action for checking identity)

if (! $this->getServiceLocator()
                 ->get('AuthService')->hasIdentity()){
            return $this->redirect()->toRoute('login');
}

this is not the good practice so help me to reduce to call once for all the action() method. Unauthorised user will redirect to login form

Thanks

Amit Kumar Sahu
  • 495
  • 6
  • 15

1 Answers1

0

One option is to create a method that fires "on dispatch" to your controller:

class YourController extends AbstractActionController {

public function onDispatch($event){
    $this->yourIdentityCheckFunction();
    return parent::onDispatch($event);
}
//your other actions/identityCheck methods etc...

}

STLMikey
  • 1,210
  • 7
  • 19