Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter flashdata not working after redirect

I have set the flash data like this

$this->session->set_flashdata('dispMessage','my message is here'));

I found that message in session library but not display in redirect page. and I am use the codeigniter version 2.2.0.

Can anyone help...?

like image 963
Paras Dalsaniya Avatar asked Jun 10 '26 22:06

Paras Dalsaniya


2 Answers

According to the session class page of the manual:

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted").

Try preserving the flashdata in your script immediately prior to redirecting as follows:

$this->session->keep_flashdata('dispMessage');
like image 152
Dbmeister Avatar answered Jun 12 '26 10:06

Dbmeister


// Set flash data 
$this->session->set_flashdata('dispMessage', 'This is my message');
// After that you need to used redirect function instead of load view such as 
redirect("yourcontroller/controllermethod");

// Get Flash data on view 
$this->session->flashdata('dispMessage');
like image 20
Jigs Virani Avatar answered Jun 12 '26 12:06

Jigs Virani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!