【发布时间】:2017-04-24 05:54:43
【问题描述】:
我正在尝试设置一个 zend 框架 3 MVC Web 应用程序以使用会话存储。根据本网站的信息--
一切都很好。我在我的控制器中获得了会话变量,我可以将数据保存到会话容器中。问题是,我保存到容器中的数据在后续调用中不存在。我正在从一页保存搜索条件并重定向到第二页以进行搜索并返回结果。当我进入第二页时,会话数据不存在。
在 config\global.php 我有 --
return [
'session_config' => [
// Cookie expires in 1 hour
'cookie_lifetime' => 60*60*1,
// Stored on server for 30 days
'gc_maxlifetime' => 60*60*24*30,
],
'session_manager' => [
'validators' => [
RemoteAddr::class,
HttpUserAgent::class,
],
],
'session_storage' => [
'type' => SessionArrayStorage::class,
],
];
在 application\module.php 中我修改了 onBoostrap
public function onBootstrap(MvcEvent $event)
{
$application = $event->getApplication();
$svcMgr = $application->getServiceManager();
// Instantiate the session manager and
// make it the default one
//
$sessionManager = $svcMgr->get(SessionManager::class);
}
我创建了一个 IndexControllerFactory
class IndexControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
$requestedName, array $options = null)
{
// Get access to session data
//
$sessionContainer = $container->get('Books\Session');
return new IndexController($sessionContainer);
}
}
修改了我的 IndexController 以添加构造方法
class IndexController extends AbstractActionController
{
private $session;
public function __construct(Container $session)
{
$this->session = $session;
}
在 application\module.config.php 我有这个
'controllers' => [
'factories' => [
Controller\IndexController::class => Controller\Factory\IndexControllerFactory::class,
],
],
'session_containers' => [
'Books\Session'
],
【问题讨论】:
标签: php session zend-framework zend-framework3