gpt4 book ai didi

php - Zend 2 错误 : Uncaught exception 'Zend\Stdlib\Exception\InvalidArgumentException'

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:55 24 4
gpt4 key购买 nike

我通过 bootstarp 方法从布局上的 Zend 2 session 容器中检索数据。

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;
}

现在我有时(不总是)遇到以下错误

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

问题是什么?

最佳答案

请试试这个:

在 Module.php 文件中 --->

use Zend\Session\Config\SessionConfig, Zend\Session\SessionManager,
Zend\Session\Container, Zend\Mvc\MvcEvent;
// other libraries

public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$sm = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);

$config = $sm->get('Config');

$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();

$user = $this->userSession($sm);
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->user = ($user) ? $user: false;
}

在 module.config.php 文件中 --->

return array(
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true
),
);

希望这会给您一些解决问题的想法。谢谢:)

关于php - Zend 2 错误 : Uncaught exception 'Zend\Stdlib\Exception\InvalidArgumentException' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24817449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com