I'm using CodeIgniter 3 and the flashdata I set on that project is not cleared even after a redirect. It still being shown after the page is refreshed or visit the page again. How can I fix this issue?
A function in a controller.
public function updateDonor($donor)
{
$birthDate = $this->input->post('donordob');
$currentDate = date("Y-m-d");
$age = date_diff(date_create($birthDate), date_create($currentDate));
$this->form_validation->set_rules('donorname', 'Donor Name', 'required');
$this->form_validation->set_rules('donornic', 'Donor NIC', 'required');
$this->form_validation->set_rules('donordob', 'Donor DOB', 'required');
$this->form_validation->set_rules('donorweight', 'Donor Weight', 'required');
$this->form_validation->set_rules('donormobile', 'Donor Mobile', 'required');
if ($this->form_validation->run()) {
$data = [
'DonorName' => $this->input->post('donorname'),
'DonorNIC' => $this->input->post('donornic'),
'DonorDOB' => $this->input->post('donordob'),
'DonorAge' => $age->format("%y"),
'DonorWeight' => $this->input->post('donorweight'),
'DonorMobile' => $this->input->post('donormobile'),
];
$this->load->model('Donor_Model');
$data['donor'] = $this->Donor_Model->updateDonor($data, $donor);
$this->session->set_flashdata('donorupdated', 'Donor detailed updated successfully!');
redirect(base_url('index.php/staff/viewdonors'));
} else {
$this->editDonors($donor);
}
}
Code in the view
<?php if ($this->session->flashdata('donorupdated')) { ?>
<script>
alertify.set('notifier', 'position', 'top-right');
alertify.success("<?php echo $this->session->flashdata('donorupdated'); ?>")
</script>
<?php } ?>