Php 如何使用ZF3访问会话容器?
我ḿ 使用ZF3,我正在构建一个服务,该服务将提供对应用程序会话容器的应用程序范围的分段访问。此服务称为SessionContainerManager,具有检索和更新用户标识、用户ACL等的方法。我的代码:Php 如何使用ZF3访问会话容器?,php,session,zend-framework,zend-framework3,zf3,Php,Session,Zend Framework,Zend Framework3,Zf3,我ḿ 使用ZF3,我正在构建一个服务,该服务将提供对应用程序会话容器的应用程序范围的分段访问。此服务称为SessionContainerManager,具有检索和更新用户标识、用户ACL等的方法。我的代码: namespace User\Service; class SessionContainerManager { /** * Service container. * @var Zend\Service\Container */ private
namespace User\Service;
class SessionContainerManager
{
/**
* Service container.
* @var Zend\Service\Container
*/
private $sessionContainer;
public function __construct($sessionContainer)
{
$this->sessionContainer = $sessionContainer;
}
public function getACLList()
{
return $this->sessionContainer->aclList;
}
public function setACLList($aclList)
{
$this->sessionContainer->aclList = $aclList;
}
public function getIdentity()
{
return $this->sessionContainer->identity;
}
public function setIdentity($identity)
{
$this->sessionContainer->identity = $identity;
}
}
及其工厂:
namespace User\Service\Factory;
use Interop\Container\ContainerInterface;
use User\Service\SessionContainerManager;
use Zend\Session\Container;
class SessionContainerManagerFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$sessionContainer = $container->get(\Zend\Session\Container::class);
return new SessionContainerManager($sessionContainer);
}
}
在module.config中:
'service_manager' => [
'factories' => [
Service\SessionContainerManager::class => Service\Factory\SessionContainerManagerFactory::class,
],
运行应用程序时,我遇到以下错误:
File:
/home/renato/project/dev/fways/php/fways/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:670
Message:
Unable to resolve service "Zend\Session\Container" to a factory; are you certain you provided it during configuration?
请帮助使此会话容器正常工作。这是由缓存的模块配置引起的。它第一次生成是为了加快读取配置。因此,在添加新的服务配置后,请始终删除
数据/cache/module config cache.application.config.cache.php中的缓存。如果未找到缓存,将自动创建缓存。这是由缓存的模块配置引起的。它第一次生成是为了加快读取配置。因此,在添加新的服务配置后,请始终删除data/cache/module config cache.application.config.cache.php中的缓存。如果找不到,将自动创建缓存。检查此链接
可能你一开始没有收到这个包裹。如果它不在您的composer中,请尝试以下方法添加它:
php composer.phar require zendframework/zend-session
检查此链接
可能你一开始没有收到这个包裹。如果它不在您的composer中,请尝试以下方法添加它:
php composer.phar require zendframework/zend-session