I'm trying to set up a zend framework 3 MVC web app to use session storage. Following the information from this website --
It all works well. I get the session variable in my controller and I can save data to the session container just fine. The problem is, the data I save to the container is NOT there on subsequent calls. I'm saving search criteria from one page and doing a redirect to a second page to do the search and return the results. The session data is not present when I enter 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 have modified 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);
}
I created an 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);
}
}
Modified my IndexController to add a constructor method
class IndexController extends AbstractActionController
{
private $session;
public function __construct(Container $session)
{
$this->session = $session;
}
In application\module.config.php i have this
'controllers' => [
'factories' => [
Controller\IndexController::class => Controller\Factory\IndexControllerFactory::class,
],
],
'session_containers' => [
'Books\Session'
],