2
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);
}
}
這是一個優先考慮;一個事件的優先級值越高,相對於其他事件就會越早觸發 –