I retrieve data from Zend 2 session container on layout via bootstarp method.
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$sm = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$user = $this->getUser($sm);
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->user = ($user) ? $user: false;
}
public function getUser($sm)
{
$user= false;
$userTable= $sm->get('User\Model\UserTable');
$userSession = new Container('userSession');
//RETRIEVE USER FROM DB
return $user;
}
Now i'm getting following error sometimes (not always)
Fatal error: Uncaught exception 'Zend\Stdlib\Exception\InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php:184 Stack trace: #0
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php(411): Zend\Stdlib\ArrayObject->exchangeArray(NULL) #1 [internal function]: Zend\Stdlib\ArrayObject->unserialize('a:4:{s:7:"stora...') #2
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start() #3
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\Session\SessionManager->start() #4
/var/www/T2oRecruitment/app/module/Application/Module.php(22): Zend\Session\AbstractContainer->__construct('userSession') #5
/var/www/T2oRecruitment/app/module/Application/Module.php(43): Application\Module->getUser(Object(Zend\S in /var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 184
What is the issue ?