I am using codeigniter 3 framework, where i use toastr notification. When i save a page i get success message from toastr, the same message is repeating if i reload or navigate to another page. I don’t have any idea why its happening. Please help me out to get the issue fixed.
Controller:
$this->session->set_flashdata('success', DELETE_MSG)
Script:
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "100",
"hideDuration": "1000",
"timeOut": "3500",
"extendedTimeOut": "60000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
<?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 } ?>
I tried to change the configuration of the toastr but no luck.
2
Answers
I’m not a CodeIgniter expert, but you said you have this code in a view:
First of all, it doesn’t seem like the best place to add this type of code.
Second, if it’s indeed in a view, maybe it’s been called on every request before you call
flashdata
?Make sure your logic is correct and that you are not calling
set_flashdata
on every request.Set flash message in your controller after saving or making a request.