How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
Flash message set in codeigniter. What is flash message? Flash message is notifications that pop up on your website that is flash messages.
You need flash message when you so your notification in a pop up and your work is done the you so a success or error message using flash message.
How to set flash message in your codeigniter project, follow the code
Model :
function user_signup($data){ $query=$this->db->insert('user_signup',$data); if($query){ $this->session->set_flashdata('category_success', 'User Signup Succcessful'); redirect('view_page'); } else{ $this->session->set_flashdata('category_error', 'Something is wrong. Error!!'); redirect('view_page'); } }
There I write a insert query code. When insert query is done or work properly then set a success message in a session variable and if it’s not work properly then set error message in a error session variable.
View :
<?php if ($this->session->flashdata('category_success')) { ?> <h2> <?php echo $this->session->flashdata('category_success'); ?> </h2> <?php } ?> <?php if ($this->session->flashdata('category_error')) { ?> <h2> <?php echo $this->session->flashdata('category_error'); ?> </h2> <?php } ?>
Now you sow your message or notification in a pop up, But I show the message in a heading tag(<h2>). If you want to show a pop up you can apply this code in a pop up box.
Related posts