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
I had the same problem. After checking the code I have found, that I am calling $this->session->sess_destroy();
, which causes the problem.
As I am observing about codeigniter flashdata. When I use it in second request using codeigniter redirect() method it is working fine in mozila but in the case of chrome it is not working.
I had Chrome developer console open and flashdata was removed. After closing it and retrying it works. Version 71.0.3578.98 (Official Build) (64-bit)
I had that problem too. I don't remember where I saw but here's my solution.
redirect('url/myurl','refresh');
CodeIgniter didn't treated redirect as another request. So flashdata wasn't set in the redirect, but it was on the next page I loaded.
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');
}
I know I am very late but I was having this problem and I couldn't believe that in my case the solution was very easy
just replace
$this->session->flashdata('message');
to
print_r($this->session->flashdata('message'));