[英]How to get access to a session container using ZF3?
我使用ZF3,我正在構建一個服務,它將提供對應用程序會話容器的應用程序范圍的分段訪問。 此服務稱為SessionContainerManager,將具有檢索和更新用戶身份,用戶ACL等的方法。我的代碼:
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?
幫助贊賞使這個會話容器工作。
檢查此鏈接是否與zf3中的Sessions一起使用可能您沒有首先獲得此包。 如果它不在您的作曲家中,請嘗試將其添加:
php composer.phar require zendframework/zend-session
由模塊配置緩存引起的。 它是在第一時間生成的,以加快讀取配置。 因此,添加新服務配置后,請始終刪除data/cache/module-config-cache.application.config.cache.php
。如果未找到,將自動創建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.