【问题标题】:Zend_Auth Identity not persisting between controllersZend_Auth 身份不在控制器之间持续存在
【发布时间】: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


【解决方案1】:

Zend_Session::rememberMe();在引导程序中解决了这个问题

【讨论】:

    猜你喜欢
    • 2011-07-14
    • 2019-05-23
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多