Question

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $event->getSharedManager()
          ->attach('Zend\Mvc\Controller\AbstractActionController',
                    'dispatch', 
         function($e) {
              $controller = $e->getTarget();

             //check if logged in, setting up the userid variable of controllers
            if ($e->getApplication()->getServiceManager()->get('AuthService')
                                            ->hasIdentity()) {
                   $users = $e->getApplication()->getServiceManager()
                            ->get('SanAuth\Model\AuthStorage')->read();

                   $controller->userid = $users['id'];
             }
        }, 100);
    }
}
Was it helpful?

Solution

From the documentation:

attach attach(string $event, callback $callback, int $priority)

Attaches $callback to the EventManager instance, listening for the event $event. If a $priority is provided, the listener will be inserted into the internal listener stack using that priority; higher values execute earliest. (Default priority is “1”, and negative priorities are allowed.)

Read more here: http://framework.zend.com/manual/2.0/en/modules/zend.event-manager.event-manager.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top