How to set Flashdata in Codeigniter
This page all about how to set flashdata in Codeigniter. Codeigniter has a very good
feature like one time show message in view page. One time means very next server request is carry the message, then automatically it unset after one time page refresh. This is feature is called as flashdata. Before redirect page from controller we have to set that message , which we have to show in view page.
1 |
$this->session->set_flashdata('message_name', 'This is a message.'); |
Now We can set this in our controller.. like below example.
1 2 3 |
$this->session->set_flashdata('message_name', 'This is my message'); // After that you need to used redirect function instead of load view such as redirect("/signup"); |
Now How to show in view page
1 |
$this->session->flashdata('message_name'); |
NB:
If there are multiple redirect the flashdata may loss. So to keep safe for next additional request, we have to use
1 2 |
$this->session->keep_flashdata('item'); $this->session->keep_flashdata(array('item1', 'item2', 'item3')); |