Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend_Auth-当我设置自定义存储命名空间时,当我重定向到新控制器时,它不存在_Php_Zend Framework_Zend Auth - Fatal编程技术网

Php Zend_Auth-当我设置自定义存储命名空间时,当我重定向到新控制器时,它不存在

Php Zend_Auth-当我设置自定义存储命名空间时,当我重定向到新控制器时,它不存在,php,zend-framework,zend-auth,Php,Zend Framework,Zend Auth,在我的条目控制器中,我设置: 这项工作: $authadapter = new Test_Auth_Adapter_DbTable($db); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authadapter); $data = $authadapter->getResultRowObject(null, 'password'); $auth->getStorage()->write

在我的
条目
控制器中,我设置:

这项工作:

$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');
当我使用调试器时,我可以在$\u会话变量中看到它设置了所有正确的数据,但是在设置了数据并重定向到所需的目标后,$\u会话变量不再设置,因此我无法访问任何内容

被重定向到的页面将通过以下方式检查身份验证:

$this->auth = Zend_Auth::getInstance();
        if (!$this->auth->hasIdentity()) {
            $this->_redirector->gotoUrl('/entry');
        }
为什么这样不行

试试这个:

$this->auth = Zend_Auth::getInstance();
$this->auth->setStorage(new Zend_Auth_Storage_Session('Test_User'));
if (!$this->auth->hasIdentity()) {
    $this->_redirector->gotoUrl('/entry');
}
问题是,如果不设置存储类,它将默认使用Zend_Auth_存储会话和Zend_Auth命名空间。由于会话数据不在该名称空间中,Zend_Auth看不到它,其行为就好像用户没有登录一样

根据应用程序的结构(以及身份验证在其中所占的比例),您可能希望在引导方法中执行此操作,因此只需执行一次:

protected function _initAuth()
{
    $auth = Zend_Auth::getInstance();
    $auth->setStorage(new Zend_Auth_Storage_Session('Test_User'));

    return $auth;
}
试试这个:

$this->auth = Zend_Auth::getInstance();
$this->auth->setStorage(new Zend_Auth_Storage_Session('Test_User'));
if (!$this->auth->hasIdentity()) {
    $this->_redirector->gotoUrl('/entry');
}
问题是,如果不设置存储类,它将默认使用Zend_Auth_存储会话和Zend_Auth命名空间。由于会话数据不在该名称空间中,Zend_Auth看不到它,其行为就好像用户没有登录一样

根据应用程序的结构(以及身份验证在其中所占的比例),您可能希望在引导方法中执行此操作,因此只需执行一次:

protected function _initAuth()
{
    $auth = Zend_Auth::getInstance();
    $auth->setStorage(new Zend_Auth_Storage_Session('Test_User'));

    return $auth;
}

成功了。我假设在login controller操作中调用setStorage()会告诉ZF该特定名称空间已经存在。我没有意识到我必须告诉它写它,然后手动告诉它检查它(因为Zend_Auth是自动的,我假设它对任何已设置的名称空间都是自动的)。在引导中设置它时,我们如何使用控制器中的这个存储来
$authStorage=$Auth->getStorage()$authStorage->write($identity)。请告诉我是谁干的。我假设在login controller操作中调用setStorage()会告诉ZF该特定名称空间已经存在。我没有意识到我必须告诉它写它,然后手动告诉它检查它(因为Zend_Auth是自动的,我假设它对任何已设置的名称空间都是自动的)。在引导中设置它时,我们如何使用控制器中的这个存储来
$authStorage=$Auth->getStorage()$authStorage->write($identity)。请引导