How to show success message using codeigniter? How to show success message using codeigniter? codeigniter codeigniter

How to show success message using codeigniter?


Just add a flash data (one time session usage) after insertion:

} else {    $roomdata = array(        'room_type' => $this->input->post('roomType'),        'room_name' => $this->input->post('roomName'),       'room_details' => $this->input->post('roomDetails')    );    $this->config_mdl->roomAdd($roomdata);    // set flash data    $this->session->set_flashdata('msg', 'Room added');    redirect('controller_name/addRoom');}  

Then in the view (addRoom):

<?php if($this->session->flashdata('msg')): ?>    <p><?php echo $this->session->flashdata('msg'); ?></p><?php endif; ?>


use cdnjs

https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.jscss https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css

call with query call

$this->session->set_flashdata('error','Crediancial is wrong');<?phpif($this->session->flashdata('notice') != ''){echo '<script>toastr.warning("'.$this->session->flashdata('notice').'","Notice");</script>';}if($this->session->flashdata('error') != ''){echo '<script>toastr.error("'.$this->session->flashdata('notice').'","Error");</script>';}if($this->session->flashdata('success') != ''){echo '<script>toastr.success("'.$this->session->flashdata('success').'","Success");</script>';}?>


After getting flash data, for redirect we can use below function for auto refresh page in Codeigniter:

header('refresh:3; url=' . base_url().'/admin_folder/adminController');