【发布时间】:2012-10-01 13:42:16
【问题描述】:
Zend Framework 1.11 和 Doctrine 2 相当新。
我已经使用 Doctrine 成功创建了登录等。
我目前的问题是,当我留在登录所在的控制器内时,Zend_Auth 实例工作正常。
如果我尝试在任何其他控制器中确定 Zend_Auth::getInstance->HasIdentity() 的状态,它会返回空白。
如果我然后返回到驻留在控制器中包含登录/身份验证的任何页面,hasIdentity 工作正常。
我什至尝试过写入存储,但这并没有带来任何乐趣。
我的验证码如下,点击登录后调用的动作(在MembersareaController中)
public function authAction()
{
$this->_helper->viewRenderer->setNoRender(true);
$loginForm = new Application_Model_Login();
if($this->getRequest()->isPost()){
$usr = "";
$pwd = "";
$KeepLoggedIn = false;
$message = "";
$usr = $this->_getParam('username');
$pwd = $this->_getParam('password');
$pwdMd5 = md5($pwd);
if($usr !== "" && $pwd !== ""){
$GDSAdaptor = new ZC_Auth_Adapter($usr, $pwdMd5);
$result = \Zend_Auth::getInstance()->authenticate($GDSAdaptor);
if(\Zend_Auth::getInstance()->hasIdentity()){
$this->flashMessenger->addMessage(LOGIN_SUCCESS);
$this->_redirect('/membersarea/index');
}else{
$this->flashMessenger->addMessage(LOGIN_INVALID);
}
}else{
$this->flashMessenger->addMessage(LOGIN_MISSING_FORMVAL);
$this->_redirect('/membersarea/login');
}
}
尝试使用以下代码查看一个人登录到 IndexController 不会产生任何结果。 hasIdentity 返回一个空白值。
public function indexAction()
{
if(Zend_Auth::getInstance()->hasIdentity())
{
$msg = "hasIdentity: YES";
}else{
$msg = "hasIdentity: NO";
}
$this->view->msg = $msg;
}
【问题讨论】:
-
您确定您的 PHP 会话的 cookie 设置为正确的域吗?我认为您应该使用 firebug 进行验证
-
嗨。感谢您的回复。我已经使用 Firebug 比较了两者之间的 cookie 信息,并且 cookie 信息是相同的。
-
我注意到该域有两个单独的 cookie,具有不同的 PHPSESSION id 并且路径不同。一个将路径设置为“/membersarea”,这是带有身份验证内容的控制器,第二个设置为“/”,即主页。
标签: zend-framework frameworks identity zend-auth