我試圖在ZF2應用程序中實現身份驗證模塊,我完全按照我在官方文檔中找到的方式執行,但是我得到這個錯誤:致命錯誤:調用未定義的方法DoctrineModule Authentication Adapter ObjectRepository :: setIdentityValue()
Fatal error: Call to undefined method DoctrineModule\Authentication\Adapter\ObjectRepository::setIdentityValue() in DOCROOT/module/Login/src/Login/Controller/IndexController.php on line 33
我把這個在我的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',
),
),
)
在我module.php
:
public function getServiceConfig()
{
return array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($serviceManager) {
return $serviceManager->get('doctrine.authenticationservice.orm_default');
}
)
);
}
這是我的控制器:
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;
}
}
}
任何膠水?
看看這個配置[Zend 2 + doctrine 2身份驗證適配器](http://stackoverflow.com/questions/12092091/zend-2-doctrine-2-auth-adapter) – ArrowHead
我跟着但沒有幫幫我。我的配置看起來很不錯。看看它沒有找到這個函數: 'DoctrineModule \ Authentication \ Adapter \ ObjectRepository :: setIdentityValue()' –