irwan Dwiyanto
irwan Dwiyanto

Reputation: 321

Notification after the insert of data by using bootstrap notify in CodeIgniter framework

I tried to input the data and put it into the database , and then redirect it to the front page . but I wanted to give notification to bootstrap notify after the entry database and redirect it to the front page?

This my Controllers

function insert() {

    $barcode = $this->input->post('id_barcode');

    $imageResource = Zend_Barcode::factory('code128', 'image', array('text'=>$barcode.date("Ymd")), array())->draw();
    $imageName = $barcode.'.jpg';
    $imagePath = './result/';
        if (!is_dir($imagePath)) {
            mkdir ($imagePath, 777, TRUE);
            }
    imagejpeg($imageResource, $imagePath.$imageName);   

    $this->product_m->insert_produk($imageName);
    redirect('admin/product');  
}

This script Bootstrap Notify

<script type="text/javascript">
    $(document).ready(function(){


        $.notify({
            icon: 'fa fa-check-circle',
            message: "Success <b>Entry Database</b>."

        },{
            type: 'info',
            timer: 4000
        });

    });
</script>

Upvotes: 2

Views: 4143

Answers (2)

Visarut Sae-Pueng
Visarut Sae-Pueng

Reputation: 353

Controller

   redirect('admin/product/success');  

View

<?php 
  $check_success = $this->uri->segment(3);
  if($check_success == "success"){
?>
    <script type="text/javascript">
       $(document).ready(function(){
        $.notify({
            icon: 'fa fa-check-circle',
            message: "Success <b>Entry Database</b>."

        },{
            type: 'info',
            timer: 4000
        });

     });
   </script>
<?php 
  };
?>

Upvotes: 2

Emily
Emily

Reputation: 312

You can set a session flashdata in "admin/product", for example:

In your controller:

$this->session->set_flashdata('message', 'success');
redirect('admin/product');

And in your admin/product page:

<?php 
  $message = $this->session->flashdata('message').
  if($message == "success"){
?>
    <script type="text/javascript">
       $(document).ready(function(){
        $.notify({
            icon: 'fa fa-check-circle',
            message: "Success <b>Entry Database</b>."

        },{
            type: 'info',
            timer: 4000
        });

     });
   </script>
<?php 
  };
?>

I hope to help you. Regards!

Upvotes: 3

Related Questions