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.
application/config/routes.php


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:
application/controllers/ProductDetailsController.php

load->library("session");
   }

	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:
application/views/productList.php




	My Pages for Alert
	
	




load->view('flashmessages'); ?>

application/views/flashmessages.php






Run URL

http://www.your-domain-name.com/success-product

http://www.your-domain-name.com/error-product

http://www.your-domain-name.com/warning-product

http://www.your-domain-name.com/info-product

I hope you get an idea about codeigniter alert message in controller.
I would like to have feedback on my infinityknow.com 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.

Leave a Comment