Displaying a flash message after redirect in Codeigniter

To set flashdata you need to redirect controller function

$this->session->set_flashdata('message_name', 'This is test message');

//redirect to some function
redirect("controller/function_name");

//echo in view or controller
$this->session->flashdata('message_name');


E.X
in model file

if($query){
$this->session->set_flashdata('xyzsuccess', 'Added Sucessfully ');
redirect('/xyz, 'refresh');
}else{
$this->session->set_flashdata('xyzerror', 'Added error');
redirect('/xyz', 'refresh');
}

in view file:

 if($this->session->flashdata('xyzsuccess')){echo "<div class='alert alert-success'><strong>Success!</strong> ".$this->session->flashdata('xyzsuccess')."</div>";}elseif($this->session->flashdata('xyzerror')){echo "<div class='alert alert-danger'><strong>Error!</strong> ".$this->session->flashdata('xyzerror')."</div>";}

Comments

Popular posts from this blog

What is required for it startup company ?

how to export html data to pdf in angularjs and javascript