我想使用Doctrine 2和ZF2進行身份驗證。爲了得到一些幫助,我使用了Zend 2 + doctrine 2 Auth Adapter,但是每次我打電話給$authService->authenticate($adapter);
時,都會收到類「'不存在的錯誤。Zend2 + Doctrine2身份驗證
看來,我的module.config.php配置不會被使用。它顯示是這樣的:
'authenticationadapter' => array(
'orm_default' => array(
'objectManager' => 'doctrine.entitymanager.orm_default',
'identityClass' => 'Profile\Entity\User',
'identityProperty' => 'username',
'credentialProperty' => 'password',
),
),
但是,如果我在authService上做了var_dump,所有集都是空的。 在我的服務,我想要做的登錄我打電話
$authAdapter = $this->getAuthAdapter();
$authAdapter->setIdentityValue($username);
$authAdapter->setCredentialValue($password);
從$ authAdapter轉儲告訴我,IdentityValue和CredentialValue 設置正確。
在$ authAdabter其他的事情是:
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
的getAuthAdapter這樣表示:
public function getAuthAdapter()
{
if (null === $this->authAdapter) {
$this->authAdapter = $this->getServiceManager()
->get('doctrine.authenticationadapter.ormdefault');
}
return $this->authAdapter;
}
這樣可以有一個人告訴我如何正確設置的選項?
好吧,我改:
然後你也以類似的方式使用它在控制器但現在它告訴我'Zend \ ServiceManager \ ServiceManager :: get無法爲doctrine.authentication.orm_default提取或創建一個實例。如果(null === $ this-> authAdapter){this-> authAdapter = $ this-> getServiceManager() - > get('doctrine.authentication()),則將getter改爲'public function getAuthAdapter() { 。orm_default'); } return $ this-> authAdapter;' – 2013-03-02 15:28:01
查看更新的答案 – hohner 2013-03-02 15:32:15
感謝您的幫助。現在只剩下一個問題了。在'$ authResult = $ authService-> authenticate();'後我得到一個空白頁面。沒有錯誤,沒有。 – 2013-03-02 15:56:32