In this tutorial we will learn about CodeIgniter Flashdata. During web application building, we only need to store some data for one time and then delete those data. For instance, to display an error message or message. We have to do it manually in PHP, but CodeIgniter made it easy for us. Flash data is only available in CodeIgniter until the next request and is automatically deleted.

Add CodeIgniter Flashdata

As shown below, we can simply store flash data.

$this->session->mark_as_flash('item');
  • mark_as_flash() – For this purpose the function is used, which only takes one value argument to be saved. We can also save multiple values through an array.
  • set_flashdata() – You can also use a function that takes two arguments, names and values, as shown below. We can pass an array, too.
$this->session->set_flashdata('item','value');

Retrieve CodeIgniter Flashdata

Flashdata can be retrieved using the flashdata() function which takes one argument of the item to be fetched as shown below. flashdata() function makes sure that you are getting only flash data and not any other data.

$this->session->flashdata('item');

If you don’t pass any argument, you can use the same function to get an array.