Tôi muốn có xác thực bằng Doctrine 2 và ZF2. Để nhận được một số trợ giúp tôi đã sử dụng Zend 2 + doctrine 2 Auth Adapter, nhưng mỗi khi tôi gọi số $authService->authenticate($adapter);
tôi đều gặp lỗi khi lớp học 'không tồn tại.Xác thực Zend2 + Doctrine2
Có vẻ như cấu hình từ module.config.php của tôi đã thắng # t được sử dụng. Nó hiển thị như sau:
'authenticationadapter' => array(
'orm_default' => array(
'objectManager' => 'doctrine.entitymanager.orm_default',
'identityClass' => 'Profile\Entity\User',
'identityProperty' => 'username',
'credentialProperty' => 'password',
),
),
Nhưng nếu tôi thực hiện một var_dump trên authService tất cả các bộ là rỗng. Trong dịch vụ của tôi, nơi tôi muốn làm đăng nhập tôi gọi
$authAdapter = $this->getAuthAdapter();
$authAdapter->setIdentityValue($username);
$authAdapter->setCredentialValue($password);
Một bãi từ $ authAdapter nói với tôi rằng IdentityValue và CredentialValue được thiết lập một cách chính xác.
Những điều khác trong $ authAdabter là:
protected 'options' =>
object(DoctrineModule\Options\Authentication)[281]
protected 'objectManager' =>
object(Doctrine\ORM\EntityManager)[248]
private 'config' =>
object(Doctrine\ORM\Configuration)[250]
...
private 'conn' =>
object(Doctrine\DBAL\Connection)[252]
...
private 'metadataFactory' =>
object(Doctrine\ORM\Mapping\ClassMetadataFactory)[266]
...
private 'repositories' =>
array (size=0)
...
private 'unitOfWork' =>
object(Doctrine\ORM\UnitOfWork)[267]
...
private 'eventManager' =>
object(Doctrine\Common\EventManager)[242]
...
private 'hydrators' =>
array (size=0)
...
private 'proxyFactory' =>
object(Doctrine\ORM\Proxy\ProxyFactory)[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
Các getAuthAdapter thấy như thế này:
public function getAuthAdapter()
{
if (null === $this->authAdapter) {
$this->authAdapter = $this->getServiceManager()
->get('doctrine.authenticationadapter.ormdefault');
}
return $this->authAdapter;
}
Vì vậy, có thể một số một cho tôi biết làm thế nào để thiết lập các tùy chọn một cách chính xác?
Được rồi tôi thay đổi nhưng bây giờ nó cho tôi biết 'Zend \ ServiceManager \ ServiceManager :: get không thể lấy hoặc tạo một cá thể cho doctrine.authentication.orm_default'. Tôi thay đổi getter thành 'hàm public getAuthAdapter() { if (null === $ this-> authAdapter) { $ this-> authAdapter = $ this-> getServiceManager() -> get ('doctrine.authentication .orm_default '); } trở $ this-> authAdapter; ' –
Xem cập nhật câu trả lời – hohner
Nhờ sự giúp đỡ của bạn. Bây giờ chỉ còn một vấn đề. Sau '$ authResult = $ authService-> authenticate();' tôi nhận được một trang trắng tinh. Không có lỗi, không có gì. –