在我的entry
控制器中,我设置:
这有效:
$authadapter = new Test_Auth_Adapter_DbTable($db);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authadapter);
$data = $authadapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);
$this->_redirector->gotoUrl('/main');
这不会:
$authadapter = new Test_Auth_Adapter_DbTable($db);
$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session('Test_User')); //the only difference
$result = $auth->authenticate($authadapter);
$data = $authadapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);
$this->_redirector->gotoUrl('/main');
当我使用调试器时,我可以看到它在 $_SESSION var 中设置了所有正确的数据,但是在设置了数据并且我重定向到所需的目的地之后,$_SESSION var 不再设置,因此我无法访问东西!
被重定向到检查身份验证的页面:
$this->auth = Zend_Auth::getInstance();
if (!$this->auth->hasIdentity()) {
$this->_redirector->gotoUrl('/entry');
}
为什么这不起作用?