I use CodeIgniter 2.1.0, i want after insert data in database get a message like \"Your information was successfully updated.\". For this work i have in CI_Controller follow
404 (not found) count as 1 server request. it will remove your flashdata.
From the Codeigniter Session Class documentation, regarding Flashdata we can read:
CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared.
Your problem might be that when you redirect, the process takes more than one request, clearing your flashdata.
To see if that's the case, just add the following code to the constructor of the controller you are redirecting to:
$this->session->keep_flashdata('message');
This will keep the flashdata for another server request, allowing it to be used afterwards.
Using sessions with database has caused me issues at times. I recommend setting $config['sess_use_database'] = FALSE;
in the config.php and see if the flashdata works fine.
// Set flash data in our controller file
$this->session->set_flashdata('sessionkey', 'Value');
// After that we need to used redirect function
redirect("admin/signup");
// Get Flash data on view
$this->session->flashdata('sessionkey');
You can also use database for the sessions, but you have to set the config items:
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = FALSE;
In that way the session flashdata will work again
I use this for flash data and it's easy to use. first, need to you have creat session and then in your controllers' method use this just before where you want to redirect your page.
On Controller after creating a session and don't forget to load session and url library.
$this->session->set_flashdata('success', 'Oops. This email id already exist.' );
redirect("You Mehod or page");
In this case, you no need to go to your particular view page to add extra php code.
And on footer.php in view past this script code
<!-- Code for flashdata toaster -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
<script type="text/javascript">
<?php if($this->session->flashdata('success')){ ?>
toastr.success("<?php echo $this->session->flashdata('success'); ?>");
<?php }else if($this->session->flashdata('error')){ ?>
toastr.error("<?php echo $this->session->flashdata('error'); ?>");
<?php }else if($this->session->flashdata('warning')){ ?>
toastr.warning("<?php echo $this->session->flashdata('warning'); ?>");
<?php }else if($this->session->flashdata('info')){ ?>
toastr.info("<?php echo $this->session->flashdata('info'); ?>");
<?php } ?>
</script>
<!-- End of flashdata script -->
Good luck and hope it will help for your problem.