Skip to content

Instantly share code, notes, and snippets.

@SocalNick
Created November 10, 2012 01:06
Show Gist options
  • Save SocalNick/4049346 to your computer and use it in GitHub Desktop.
Save SocalNick/4049346 to your computer and use it in GitHub Desktop.
Initialize Session Oddity
<?php
namespace Application;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Session\SessionManager' => function($sm) {
return new \Zend\Session\SessionManager();
},
),
);
}
public function onBootstrap(MvcEvent $e)
{
$this->initSession($e);
}
// DOES NOT WORK
public function initSession($e)
{
$app = $e->getApplication();
$serviceManager = $app->getServiceManager();
$session = $serviceManager->get('Zend\Session\SessionManager');
$session->setName('IGNPHANTOM');
}
// WORKS
public function initSession($e)
{
$session = new \Zend\Session\SessionManager();
$session->setName('IGNPHANTOM');
}
}
@mwillbanks
Copy link

That is REALLY odd. I'm actually baffled here.

@mwillbanks
Copy link

fyi; you may want to also set the default manager to the Container, this should solve the Zend\Authenticate issue since it attempts to create a container on your behalf:

public function initSession($e)
{
    $session = new \Zend\Session\SessionManager();
    $session->setName('IGNPHANTOM');
    \Zend\Session\Container::setDefaultManager($session);
}

Still looking into why the session manager is borked when you're using a service factory...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment