how to display success message in codeigniter?

Today, We want to share with you how to display success message in codeigniter.In this post we will show you codeigniter flash message timeout, hear for codeigniter flash message bootstrap we will give you demo and example for implement.In this post, we will learn about notification in php demo with an example.

How to implement flash messages in PHP Codeigniter?

Step 1: Download Fresh Codeigniter 3

In First phase we will download fresh version of Codeigniter 3, so if you haven’t download yet then download from here : Download Codeigniter 3.

Step 2: Add Route

In this phase, we will add one routes for demo. this simple example is from step by step so you can check each flashmessages with demo. therefor let’s add bellow website routes in route file.

defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

$route['success-product'] = 'ProductDetailsController/success';
$route['error-product'] = 'ProductDetailsController/error';
$route['warning-product'] = 'ProductDetailsController/warning';
$route['info-product'] = 'ProductDetailsController/info';

Step 3: Add Controller

In this phase I need to create new ProductDetailsController controller, In that controller file we will write method for each flash product example.therefor let’s add with following code. you have to just copy of main file like as a welcome.php controller file:

defined('BASEPATH') OR exit('No direct script access allowed');

class ProductDetailsController extends CI_Controller {

   public function __construct() { 

	public function success()
      $this->session->set_flashdata('success', 'Product Updated successfully');
      return $this->load->view('productList');

  public function error()
      $this->session->set_flashdata('error', 'Something is wrong.');
      return $this->load->view('productList');

  public function warning()
      $this->session->set_flashdata('warning', 'Something is wrong.');
      return $this->load->view('productList');

  public function info()
      $this->session->set_flashdata('info', 'Product listed bellow');
      return $this->load->view('productList');


Step 4: Add View Files

Now at last phase we require to create “productList.php” and “flashmessages.php” view files. flashmessages.php file you can include on all the files so each time you can simply generate notification messages. So let’s create both files:

<!DOCTYPE html>
	<title>My Pages for Alert</title>
	<script src=""></script>
	<link href="" rel="stylesheet" />




<script src=""></script>
<link rel="stylesheet" type="text/css" href="">

<script type="text/javascript">

<?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')){  ?>"<?php echo $this->session->flashdata('info'); ?>");
<?php } ?>



I hope you get an idea about codeigniter alert message in controller.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.