Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flashdata not getting cleared in Codeigniter

I am using Codeigniter 2.1.4 and I have facing some issues with flashdata. When I successfully submit record I can display the flashdata message. But if go to the other page from the page where flashdata message was displayed and then go back to previous page using browser back button it shows me flashdata message again.
How to clear flashdata message once it used? I think its not the flashdata issue its cache problem. I am confused why this is happening. If its cache issue then how to remove it?

Below is code I have used,

//In the manage of controller
$this->session->set_flashdata('message', "Record updated successfully.");

// In the view of controller
$data['message'] = $this->session->flashdata('message');

// In the view page
echo $message;
like image 861
Sachin Avatar asked Sep 17 '13 09:09

Sachin


2 Answers

Flash disappears only after next refresh

like image 86
Nabil Avatar answered Nov 10 '22 04:11

Nabil


your code in controller is right

//In the manage of controller
$this->session->set_flashdata('message', "Record updated successfully.");
redirect('controller_name/function_name','refresh');

now in view use like this

if($this->session->flashdata('message')){echo $this->session->flashdata('message');}

hope it will work

like image 4
ABorty Avatar answered Nov 10 '22 03:11

ABorty