Codeigniter flash message with bootstrap

Codeigniter flash messages with bootstrap alerts.

I am going to explain you how can you set and get flash messages in codeigniter. codeigniter flash messages you can set in controller actions. Here i mentioned flash message with bootstrap when you will get success,error or warning or you want to show information at page load then you can use below code. codeingniter flash message stored in session we can easily set flash message in controller using set_flashdata() and get flash message in views using flashdata().

In the codeigniter action(function) we need to set flashdata like below script.

$this->session->set_flashdata('success', 'Information...');
OR
$this->session->set_flashdata('error', 'Information...');
OR
$this->session->set_flashdata('warning', 'Information...');
OR
$this->session->set_flashdata('info', 'Information...');

In your view file write below script and you need to load bootstrap library for alert messages in my below code i already loaded bootstrap css and js.

  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<?php if($this->session->flashdata('success')){ ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            <strong>Success!</strong> <?php echo $this->session->flashdata('success'); ?>
        </div>
    <?php }else if($this->session->flashdata('error')){  ?>
        <div class="alert alert-danger">
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            <strong>Error!</strong> <?php echo $this->session->flashdata('error'); ?>
        </div>
    <?php }else if($this->session->flashdata('warning')){  ?>
        <div class="alert alert-warning">
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            <strong>Warning!</strong> <?php echo $this->session->flashdata('warning'); ?>
        </div>
    <?php }else if($this->session->flashdata('info')){  ?>
        <div class="alert alert-info">
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            <strong>Info!</strong> <?php echo $this->session->flashdata('info'); ?>
        </div>
    <?php } ?>

Thank You.