Php 致命错误:调用未定义的方法doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue()
我正在尝试在ZF2应用程序中实现身份验证模块,我完全按照我在官方文档中发现的那样执行,但我遇到了以下错误:Php 致命错误:调用未定义的方法doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue(),php,doctrine-orm,zend-framework2,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 我把它放在m
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',
),
),
)
在my 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;
}
}
}
有胶水吗?看看这个配置:
看看这个配置:
好的,我找到了答案。似乎setIdentityValue()和setCredentialValue()方法(以及getter)不再存在。相反,要设置这些值,必须调用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;
好的,我找到了答案。似乎setIdentityValue()和setCredentialValue()方法(以及getter)不再存在。相反,要设置这些值,必须调用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;
是的,我会确认你的观点(和错误)亚瑟。 我刚刚更新到Zend 2.5,我的实际版本。 需要在中更改方法“setIdentityValue”和“setCredentialValue”: -setIdentity() -setCredential()。
有了这个更改,我的代码就可以正常工作了。是的,我会确认你的观点(和错误)亚瑟。 我刚刚更新到Zend 2.5,我的实际版本。 需要在中更改方法“setIdentityValue”和“setCredentialValue”: -setIdentity() -setCredential()。
通过此更改,我的代码可以正常工作。请查看我遵循的配置,但没有任何帮助。我的配置似乎非常正确。请注意,它找不到以下函数:
doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue()
请查看我所遵循的配置,但没有任何帮助。我的配置似乎非常正确。请注意,它没有找到以下函数:doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue()
我跟随了,但没有任何帮助。我的配置似乎非常正确。请注意,它没有找到以下函数:doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue()
我跟随了,但没有任何帮助。我的配置似乎非常正确。请注意,它找不到以下函数:doctriemodule\Authentication\Adapter\ObjectRepository::setIdentityValue()