CodeIgniter flashdata not working after redirect

时光怂恿深爱的人放手 提交于 2020-02-25 02:38:07

问题


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...?


回答1:


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');



回答2:


// 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');


来源:https://stackoverflow.com/questions/31115835/codeigniter-flashdata-not-working-after-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!