会话Flashdata在表单提交上不起作用

埃洛伊·费尔南德斯·佛朗哥(Eloy Fernandez Franco)

我正在将ion-auth“库”用于codeigniter(https://github.com/benedmunds/CodeIgniter-Ion-Auth),而flashdata出现了问题。这是一段代码摘要:

public function reset_password($code = NULL)
{
    if (!$code)show_404();
    $this->user = $this->ion_auth->forgotten_password_check($code);
    if ($this->user)
    {
        //setting the rules
        if ($this->form_validation->run() == false)
        {
            //more code
            $this->_get_csrf_nonce();
            /*
              One of the things this function (_get_csrf_nonce) makes is:
              $this->session->set_flashdata('csrfkey', $key);
              $this->session->set_flashdata('csrfvalue', $value); 
            */
            //The next thing is load the view with the form
        }
        else //form is running
        {
            echo "flashdata csrfkeyvalue: ".$this->session->flashdata('csrfvalue')."<br>";
            die;
            //more code, but not important by the moment
        }
    }
}

好了,始终提交表单时,$ this-> session-> flashdata('csrfvalue')的回声什么也没显示。
如果我做类似的事情:

private function _get_csrf_nonce(){
    /*$this->load->helper('string');
    $key   = random_string('alnum', 8);
    $value = random_string('alnum', 20);
    $this->session->set_flashdata('csrfkey', $key);*/
    $this->session->set_flashdata('csrfvalue', $value);
    redirect(base_url("auth/test"));
    //return array($key => $value);
}
public function test()
{
    echo "flashdata csrfkeyvalue: ".$this->session->flashdata('csrfvalue')."<br>";
}

在这种情况下...有效。我对表单使用的视图与此非常相似:https : //github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/views/auth/reset_password.php

谢谢。

埃洛伊·费尔南德斯·佛朗哥(Eloy Fernandez Franco)

解决方案

经过一番战斗之后,我一直在寻找可以在加载表单视图和提交表单之间进行新请求的东西...最后,我发现(我不记得了)一个通过控制器请求的javascript (根据本教程翻译一些文本:http : //www.student.kuleuven.be/~r0304874/blog/international-javascript-files-in-codeigniter.html)。我是用这种方式加载的:

<script src="<?=site_url('jsloader/login.js');?>" type="text/javascript"></script>

谢谢。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章