Art*_*tro 1 php doctrine-orm zend-framework2
我正在尝试在ZF2应用程序中实现身份验证模块,我完全按照我在官方文档中找到的那样,但我收到此错误:
Fatal error: Call to undefined method DoctrineModule\Authentication\Adapter\ObjectRepository::setIdentityValue() in DOCROOT/module/Login/src/Login/Controller/IndexController.php on line 33
Run Code Online (Sandbox Code Playgroud)
我把它放在我的module.config.php中:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
),
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Login\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
),
),
)
Run Code Online (Sandbox Code Playgroud)
在我的module.php中:
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
}
)
);
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
namespace Login\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController{
public function indexAction(){
if ($this->getRequest()->isPost()) {
if($this->authenticate()){
return new ViewModel(array(
'error' => 'Your authentication credentials is valid!',
));
}else{
return new ViewModel(array(
'error' => 'Your authentication credentials are not valid',
));
}
}else{
return new ViewModel(array('error' => ''));
}
}
public function authenticate(){
$data = $this->getRequest()->getPost();
$authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
$adapter = $authService->getAdapter();
$adapter->setIdentityValue($data['email']);
$adapter->setCredentialValue($data['password']);
$authResult = $authService->authenticate();
if ($authResult->isValid()) {
return true;
}else{
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
有胶水吗?
好的,我找到了答案.似乎方法setIdentityValue()和setCredentialValue()(getters也)不再存在.而不是设置这些值,您必须调用setIdentity()和setCredential().似乎这最近发生了变化,因为我一无所知,而我的应用程序曾经工作过,突然间,停止工作导致这些变化.这就是我意识到方法改变了他们的标志:
$authService = $this->getServiceLocator() >get('Zend\Authentication\AuthenticationService');`
$adapter = $authService->getAdapter();
$class_methods = get_class_methods($adapter);
echo "<pre>";print_r($class_methods);exit;
Run Code Online (Sandbox Code Playgroud)
并输出:
Array
(
[0] => __construct
[1] => setOptions
[2] => getOptions
[3] => authenticate
[4] => getCredential
[5] => setCredential
[6] => getIdentity
[7] => setIdentity
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1570 次 |
| 最近记录: |