CodeIgniter send and retrieve data using flash messages ?

I am gonna teach you about CodeIgniter flash messages. CI’s flash sessions functionality¬† let us to use the data for the next server request.Unlike normal sessions flash data will be destroyed permanently after next request, Therefore these can be very useful, and are typically used for showing informational or status messages for example we can use for showing success messages , error messages.. etc.

Note: Flash variables are prefaced with “flash_” so avoid this prefix in your own session names.

How to use

To use flash session in CI, we must configure session key in application/config/config.php file and we must load session library by using auto load mechanism or we can load it in controller or in action.

To add flash data :

To read or get the data from flash data:

If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.


Show me example:

For example if user redirects to index action(page) after adding, updating and deleting a record we gonna show message to the user.

Open your controller just add the line before redirect .

you can check and set failure messages also something like

now open your view file (Example : test_view.php). Write code someting like shown below

Hey , we finally knew how to use flash data in CI application. Happy coding …if you get any issues and if i missed anything here let me know via comments i will update the post.Thanks.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.