How to create flash messages in Codeigniter

Let me explain about the CodeIgniter session flash message. It’s a temporarily stored value working like a session. This coding used to set success message and failure message through your controller. Let start to learn how to create CodeIgniter session flash message.

Flash session set code work with your controller functions. Session response code displays your flash view files. Generally, we will success message after submitting the form try to use session message.

Set flash data in controller

$this->session->set_flashdata('SUCCESS', "Record Added Successfully!!");

Read flash data and display in your view file

<?php if ($this->session->flashdata('SUCCESS')) { ?>
<div role="alert" class="alert alert-success">
   <button data-dismiss="alert" class="close" type="button">
	   <span aria-hidden="true">x</span><span class="only">Close</span></button>
   <?= $this->session->flashdata('SUCCESS') ?>
<?php } ?>
you may also try $this->session->flashdata()

Leave a Reply

Your email address will not be published. Required fields are marked *