Let me explain about the CodeIgniter session flash message. it's a temporarily stored value. this coding used to set success message and failure message through your controller. Let start to learn how to create CodeIgniter session flash message.
The session store data will available temporarily it will work with single server request. Once get the
next server request session data will clear automatically.
Set flash data in controller
message - flash data session name.
$this->session->set_flashdata('message', 'Sucessfully updated.');
message - It's a session temporary name you can give any name like 'delete_data', 'error_msg'
Read flash data
echo $this->session->flashdata('message');
Welcome Controller
Create sample controller class name called to welcome and set your session
<?php class Welcome extends CI_Controller { public function add_user() { //insert or update code
$this->session->set_flashdata('message', 'Successfully Added.'); $this->load->view('index'); } }
View(index.php)
I have to load the session message index file
<html>
<body>
<?php if($this->session->flashdata('message')){?> <div class="alert alert-success"> <?php echo $this->session->flashdata('message')?> </div> <?php } ?>
</body>
</html>
Sessflashesata typically used for showing informational or status messages for alert and success message example success alert message,Error message, Info messages. We can set flash lot message in same flash data name.
Thank you for visiting. if have any queries write comments below.
"To help yourself, you must be yourself. Be the best that you can be. When you make a mistake, learn from it, pick yourself up and move on. "
- Dave Pelzer
Thanks.. Nice and Simple one..
ReplyDeletethanks
ReplyDeletethanks !!! this code solved most of my problem . Simple and easy
ReplyDeleteWelcome saranraj.
Deletethanks brother... good jobs..
ReplyDeleteWelcome brother
ReplyDeleteno use
ReplyDeletehow to set flashdata on submit without redirect?
ReplyDelete