我正在尝试使用 Zend_Session_Namespace 来帮助我完成更改用户密码的任务。为此,我需要在他们第一次访问重置页面时存储他们的 GET 请求的一些值。我想用 Zend_Session_Namespace 做到这一点。然后,我想使用我保存在 Zend_Session_Namespace 中的值更新他们发布请求中的用户密码(来自同一页面)。问题是保存在 Zend_Session_Namespace 中的值在我访问它们时为空。但是,我仍然可以使用典型$_SESSION
变量来完成这项工作。有谁知道我错在哪里?我错过了一些关于使用 Zend_Session_Namespace 的提示吗?我是否需要使用 Zend_Registry 或类似的东西?
我的操作代码如下:
/**
* This handles password change
*/
public function changepasswordAction() {
$passwordForm = new Advancedsms_Form_ChangePassword();
$this->view->form = $passwordForm;
//If it is NOT post, the user has to provide recovery code and phone number
if(!$this->getRequest()->isPost()) {
$phone = filter_input(INPUT_GET, 'phone', FILTER_SANITIZE_URL);
$recovery = filter_input(INPUT_GET, 'recovery', FILTER_SANITIZE_URL);
$this->session= new Zend_Session_Namespace('RecoverySession');
$this->session->phone= $phone;
$this->session->recoveryCode = $recovery;
print_r($this->session);
$_SESSION['phone'] = $phone;
$_SESSION['recovery'] = $recovery;
}
if($this->getRequest()->isPost()) {
$params = $this->getRequest()->getParams();
print_r($params);
echo 'phone: ' . $this->session->phone .PHP_EOL;
echo 'recovery: ' . $this->session->recoveryCode . PHP_EOL;
echo $_SESSION['phone'] . ',' . $_SESSION['recovery'];
}
}