【问题标题】:show notify after save data using codeigniter使用 codeigniter 保存数据后显示通知
【发布时间】:2016-01-15 02:49:34
【问题描述】:

我试图在保存数据并将其显示在视图中时显示通知,但不运行我使用 notify.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>

【问题讨论】:

    标签: javascript php twitter-bootstrap codeigniter


    【解决方案1】:

    使用session flash data会更容易

    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 }?>
    

    【讨论】:

      【解决方案2】:

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

      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 } ?>
      

      【讨论】:

        猜你喜欢
        • 2018-06-12
        • 1970-01-01
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多