我正在使用zfcUser和zfcUserLdap来控制对应用程序后台的访问。
现在我需要添加国家/地区选择。我已更新登录表单,我可以让用户选择该国家。
我想将此国家/地区存储在存储对象中,因此后台将适用于此国家/地区。
此存储用于zfcuser和zfcuserldap,但是当我想从其他控制器获取存储时,我无法实现。
在ZfcUserLdap \ Authentication \ Adapter \中的Ldap类中,修改了authenticate方法:
public function authenticate(AuthEvent $e) {
...
$userObject = $mapper->findByUsername($identity);
if (null !== $userObject)
{
// check the password against the LDAPC directory
$auth = $mapper->authenticate($userObject->getLdapcObject(), $credential);
// check if the user belongs to the right LDAPc group
$hasSecurityGroup = $mapper->hasSecurityGroup($userObject->getLdapcObject());
if ($auth && $hasSecurityGroup)
{
$storage = $this->getStorage()->read();
$storage['identity'] = $e->getIdentity();
// set the selected country to manage the backoffice
**$storage['country'] = $country;**
$this->getStorage()->write($storage);
$this->setSatisfied(true);
$e->setCode(AuthenticationResult::SUCCESS)
->setMessages(array('Authentication successful.'))
->setIdentity($userObject);
return;
}
else
{
$e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)
->setMessages(array('Password doesn\'t match'));
$this->setSatisfied(false);
...
...
这是在身份验证过程中完成的。
在主索引控制器上,我想要恢复用户选择的国家/地区,因此我尝试读取存储而没有成功
...
try {
$storage = \ZfcUserLdap\Authentication\Adapter\Ldap::getStorage();
if ($storage->hasItem('identity'))
echo $storage->getItem('identity');
else
echo 'no esta guardada la identidad';
} catch (\Exception $e) {
echo "Caught exception $e\n";
}
...
我得到了例外:
Caught exception exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for setStorage' in /users/p0100/web/vendor/ZF2/library/Zend/ServiceManager/ServiceManager.php:495
Stack trace:
#0 /users/p0100/web/vendor/ZF2/library/Zend/ServiceManager/AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('setStorage', true)
#1 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Controller/PluginManager.php(82): Zend\ServiceManager\AbstractPluginManager->get('setStorage', NULL, true)
#2 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Controller/AbstractController.php(285): Zend\Mvc\Controller\PluginManager->get('setStorage', NULL)
#3 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Controller/AbstractController.php(300): Zend\Mvc\Controller\AbstractController->plugin('setStorage')
#4 /users/p0100/web/vendor/ZfcUserLdap/src/ZfcUserLdap/Authentication/Adapter/Ldap.php(116): Zend\Mvc\Controller\AbstractController->__call('setStorage', Array)
#5 /users/p0100/web/vendor/ZfcUserLdap/src/ZfcUserLdap/Authentication/Adapter/Ldap.php(116): Backoffice\Controller\IndexController->setStorage(Object(Zend\Authentication\Storage\Session))
#6 /users/p0100/web/module/Backoffice/src/Backoffice/Controller/IndexController.php(20): ZfcUserLdap\Authentication\Adapter\Ldap->getStorage()
#7 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Controller/AbstractActionController.php(83): Backoffice\Controller\IndexController->indexAction()
#8 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 /users/p0100/web/vendor/ZF2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#10 /users/p0100/web/vendor/ZF2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#13 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 /users/p0100/web/vendor/ZF2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 /users/p0100/web/vendor/ZF2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /users/p0100/web/vendor/ZF2/library/Zend/Mvc/Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /users/p0100/web/html/index.php(32): Zend\Mvc\Application->run()
#18 {main}
我远远不是一个着名的ZF2开发者,我做错了什么,拜托?
提前致谢