php – Zend2 Doctrine2身份验证
|
我想使用Doctrine 2和ZF2进行身份验证.为了获得一些帮助,我使用了 Zend 2 + doctrine 2 Auth Adapter,但每次调用$authService-> authenticate($adapter);我得到一个错误,该类”不存在. 看来我的module.config.php中的配置不会被使用.它显示如下: 'authenticationadapter' => array(
'orm_default' => array(
'objectManager' => 'doctrine.entitymanager.orm_default','identityClass' => 'ProfileEntityUser','identityProperty' => 'username','credentialProperty' => 'password',),
但是如果我在authService上创建了一个var_dump,那么所有的set都是null. $authAdapter = $this->getAuthAdapter(); $authAdapter->setIdentityValue($username); $authAdapter->setCredentialValue($password); 来自$authAdapter的转储告诉我IdentityValue和CredentialValue $authAdabter中的其他内容是: protected 'options' =>
object(DoctrineModuleOptionsAuthentication)[281]
protected 'objectManager' =>
object(DoctrineORMEntityManager)[248]
private 'config' =>
object(DoctrineORMConfiguration)[250]
...
private 'conn' =>
object(DoctrineDBALConnection)[252]
...
private 'metadataFactory' =>
object(DoctrineORMMappingClassMetadataFactory)[266]
...
private 'repositories' =>
array (size=0)
...
private 'unitOfWork' =>
object(DoctrineORMUnitOfWork)[267]
...
private 'eventManager' =>
object(DoctrineCommonEventManager)[242]
...
private 'hydrators' =>
array (size=0)
...
private 'proxyFactory' =>
object(DoctrineORMProxyProxyFactory)[268]
...
private 'expressionBuilder' => null
private 'closed' => boolean false
private 'filterCollection' => null
protected 'objectRepository' => null
protected 'identityClass' => null
protected 'identityProperty' => null
protected 'credentialProperty' => null
protected 'credentialCallable' => null
protected 'classMetadata' => null
protected 'storage' => null
protected '__strictMode__' => boolean true
protected 'authenticationResultInfo' => null
getAuthAdapter显示如下: public function getAuthAdapter()
{
if (null === $this->authAdapter) {
$this->authAdapter = $this->getServiceManager()
->get('doctrine.authenticationadapter.ormdefault');
}
return $this->authAdapter;
}
那么有人可以告诉我如何正确设置选项吗? 看起来您使用的是错误的配置值.如果查看DoctrineORM文档,它们将使用以下命令设置身份验证适配器的配置:'doctrine' => array(
'authentication' => array(
'orm_default' => array(
'object_manager' => 'DoctrineORMEntityManager','identity_class' => 'ApplicationEntityUser','identity_property' => 'email','credential_property' => 'password',)
因此,而不是使用authenticationadapter在module.config.php中使用身份验证;而不是使用objectManager使用object_manager等. 在Module.php中,您需要添加以下内容: use ZendAuthenticationAuthenticationService;
...
public function getServiceConfig()
{
return array(
'factories' => array(
'ZendAuthenticationAuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
}
)
);
}
在您的控制器中,您可以使用以下方法访问适配器: $authService = $this->getServiceLocator()->get('ZendAuthenticationAuthenticationService');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['login']);
$adapter->setCredentialValue($data['password']);
请关注documentation. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
