【发布时间】:2015-03-11 11:39:59
【问题描述】:
在我的应用程序(ZF2 / ORM)中,我有 3 个实体(具有单表继承)
用户
所有者扩展用户
代理扩展用户
我想使用 3 个实体进行一次身份验证(登录) 学说.authenticationservice.orm_default
module.config.php
//other doctrine config
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Application\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
'credential_callable' => function(User $user, $passwordGiven) {
return $user->getPassword() == md5($passwordGiven);
},
),
),
以及登录过程
//登录控制器.php
// ..data validation
$this->authService = $this->getServiceLocator()->get('doctrine.authenticationservice.orm_default');
$AuthAdapter = $this->authService->getAdapter();
$AuthAdapter->setIdentity($this->request->getPost('email'));
$AuthAdapter->setCredential(md5($this->request->getPost('password')));
$result = $this->authService->authenticate();
if($result->isValid()){
$identity = $result->getIdentity();
//continue
}
如何在不关心对象类型的情况下完成此过程, 当我尝试使用代理的电子邮件登录时,我收到此错误
可捕获的致命错误:传递给 Application\Module::{closure}() 的参数 1 必须是 User 的实例,给定的 Application\Entity\Owner 的实例
【问题讨论】:
标签: authentication orm doctrine-orm zend-framework2