CodeIgniter “flashdata” doesn't work

前端 未结 12 2051
灰色年华
灰色年华 2020-12-03 18:10

I use CodeIgniter 2.1.0, i want after insert data in database get a message like \"Your information was successfully updated.\". For this work i have in CI_Controller follow

12条回答
  •  醉话见心
    2020-12-03 18:50

    Except one page, I am able to display/pass values using session. I tried using the var_dump($this->session) and I get:

    ["flash:old:Array"]=> bool(false)
    ["flash:new:message"]=> string(10) "My Message"
    

    I have tried echoing the flash data within the page without redirecting just after setting the data, but the result was same. I recommend to trim down the code, and try to set session in other pages. If the problem persists check your var_dump. This might not be the solution, but I think it can help.

    UPDATE : trimming down spaces and newlines within the text worked. I was passing 2 long sentences with empty line breaks and spaces.

    if (0) //Assume this condition is false
    {   
        $this->load->view('error_page');
        // Generate validation error
    }
    else
    {
        //Show success message
        $data = array(
                    'message' => 'My message'
                               );
        $this->session->set_flashdata($data);
        $this->session->keep_flashdata($data);                      
        echo $this->session->flashdata('message');
        //echo var_dump($this->session);
        //redirect(base_url().'success_page');
    }
    

提交回复
热议问题