使用编码器点火器保存数据后显示通知


show notify after save data using codeigniter

我试图在保存数据时显示通知并将其显示在视图中,但不运行我使用通知.js . 如果有人可以帮助我?

这是我的控件保存

function save() {
    $data = array(                      
                'idsupplier' => $this->input->post('idsupplier'),
                'namasupplier' => $this->input->post('namasupplier'),
                'alamat' => $this->input->post('alamat'),
                'telp' => $this->input->post('telp'),
                'fax' => $this->input->post('fax'),
                'email' => $this->input->post('email'),
                'web' => $this->input->post('web'),
                'kontak1' => $this->input->post('kontak1'),
                'hp1' => $this->input->post('hp1'),                     
                'email1' => $this->input->post('email1'),
                'kontak2' => $this->input->post('kontak2'),
                'hp2' => $this->input->post('hp2'),                     
                'email2' => $this->input->post('email2'));  
    $this->mcrud->addsupplier($data);   
    echo '<script>Notify("Alat Baru Berhasil Ditambahkan Ke Database ", null, null, type);</script>';
    redirect('instrument/detailsupplier');

这是我的观点

                <style>
                #notifications {
                    cursor: pointer;
                    position: fixed;
                    right: 0px;
                    z-index: 9999;
                    bottom: 0px;
                    margin-bottom: 22px;
                    margin-right: 15px;
                    max-width: 300px;   
                }
                </style>
     <div id="notifications"></div>
<script>
$( document ).ready(function() {
                Notify("Alat Baru Berhasil Ditambahkan Ke Database ", null, null, type);
    });
</script>

使用会话闪存数据同样容易

function save() {
    $data = array(                      
        'idsupplier' => $this->input->post('idsupplier'),
        'namasupplier' => $this->input->post('namasupplier'),
        'alamat' => $this->input->post('alamat'),
        'telp' => $this->input->post('telp'),
        'fax' => $this->input->post('fax'),
        'email' => $this->input->post('email'),
        'web' => $this->input->post('web'),
        'kontak1' => $this->input->post('kontak1'),
        'hp1' => $this->input->post('hp1'),                     
        'email1' => $this->input->post('email1'),
        'kontak2' => $this->input->post('kontak2'),
        'hp2' => $this->input->post('hp2'),                     
        'email2' => $this->input->post('email2')); 
    );
}
$this->mcrud->addsupplier($data);  
$this->session->set_flashdata('something', 'Alat Baru Berhasil Ditambahkan Ke Database');
// Codeigniter set flash data will only work when your redirecting
redirect('instrument/detailsupplier');
}

然后在您的视野中

<?php if ($this->session->flashdata('something')) {?>
    <div id="notifications"><?php echo $this->session->flashdata('something');</div>
<?php }?>

成功时设置闪烁消息并检查闪烁消息并触发通知。请参阅下面的代码。

function save() {
    $data = array(                      
                'idsupplier' => $this->input->post('idsupplier'),
                'namasupplier' => $this->input->post('namasupplier'),
                'alamat' => $this->input->post('alamat'),
                'telp' => $this->input->post('telp'),
                'fax' => $this->input->post('fax'),
                'email' => $this->input->post('email'),
                'web' => $this->input->post('web'),
                'kontak1' => $this->input->post('kontak1'),
                'hp1' => $this->input->post('hp1'),                     
                'email1' => $this->input->post('email1'),
                'kontak2' => $this->input->post('kontak2'),
                'hp2' => $this->input->post('hp2'),                     
                'email2' => $this->input->post('email2'));  
    $this->mcrud->addsupplier($data);   
    //set flash message
    $this->session->set_flashdata('msg','Alat Baru Berhasil Ditambahkan Ke Database');
    redirect('instrument/detailsupplier');

在您的视野中

<?php if ($this->session->flashdata('msg')) {?>
     <script>
      Notify(<?=$this->session->flashdata('msg')?>, null, null, type);
     </script>
<?php } ?>