I am trying to configure the zend framework 3 MVC application to use session storage. Following the information from this site -
https://olegkrivtsov.imtqy.com/using-zend-framework-3-book/html/en/Working_with_Sessions/PHP_Sessions.html
Everything works well. I get the session variable in my controller, and I can save the data in the session container just fine. The problem is that the data that I save in the container is NOT there on subsequent calls. I save the search criteria from one page and redirect to the second page to perform a search and return the results. Session data is missing when entering the second page.
In config \ global.php I have -
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,
],
];
In application \ module.php I changed onBoostrap
public function onBootstrap(MvcEvent $event)
{
$application = $event->getApplication();
$svcMgr = $application->getServiceManager();
$sessionManager = $svcMgr->get(SessionManager::class);
}
I created an IndexControllerFactory
class IndexControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
$requestedName, array $options = null)
{
$sessionContainer = $container->get('Books\Session');
return new IndexController($sessionContainer);
}
}
IndexController
class IndexController extends AbstractActionController
{
private $session;
public function __construct(Container $session)
{
$this->session = $session;
}
\module.config.php
'controllers' => [
'factories' => [
Controller\IndexController::class => Controller\Factory\IndexControllerFactory::class,
],
],
'session_containers' => [
'Books\Session'
],