Skip to content Skip to sidebar Skip to footer

Codeigniter flash message doesn't work

Reading Time: < 1 minute

When you working in the codeigniter, you want to send message or data from controller to view files.It can be done by using flash messages.But sometimes flash message doesn’t work.It is not displaying data.So I’m going to give the solutions to this issue.

First we’ll discuss how to normally display this message through the view file from the controller.
In the controller.

-------- SYNTAX-----------------------------------
 $this->session->set_flashdata('item', 'value');
// usage
$this->session->set_flashdata('flash_message', "This is the message to the view file"));

You can put own message name instead of the “flash_message” as following example.

$this->session->set_flashdata('my_message', "This is the message to the view file"));

In the view file.

if($msg = $this->session->flashdata('my_message')){
  echo $msg;

You can get more information about the send and retrieve data using flash messages of my another post.

what are the reasons to not working the flash message?

1-Incorrect syntax

You can put custom names instead of the “set_flashdata”. Look at this example.

$this->session->set_success_flashdata('my_message', 'This is the message to the view file');
$this->session->set_flashdata('my_message', 'This is the message to the view file');

2-Sessions with database…
Using sessions with database may be caused.
In the application/config/config.php file.

 $config['sess_use_database'] = TRUE;

Here is the recommend settings.

 $config['sess_use_database'] = FALSE; // if this TRUE, put as FALSE.