CodeIgniter引导程序在删除前确认

时间:2014-04-26 10:15:18

标签: php codeigniter twitter-bootstrap

我是CI的新手,并尝试使用它来启动它。我按照本教程here

进行了操作

无济于事。

控制器:

     public function index() {
       $this->load->view('bootstrap/dt_header');
       $this->load->model('SalesModel');
       $data ['query'] = $this->SalesModel->viewallsales(); 
       $this->load->view('bootstrap/dt_footer');
     }

型号:

public function viewallsales()
{
    $this->db->select('*');
    $this->db->from('salesmonitoring');
    $this->db->join('customers', 'salesmonitoring.customer_id = customers.customer_id');
    $this->db->order_by("salesmonitoring.sales_id", "desc"); 

    $query = $this->db->get();

    return $query->result();

}

查看:

  <table class="table table-hover table-bordered" id="example">
        <thead>
        <tr>
            <td>#</td>
            <td>Transaction Date</td>
            <td>Product Code</td>
            <td>Trace Number</td>
            <td>Recipient</td>
            <td>Is Paid?</td>
            <td>Load Balance</td>
            <td>Customer</td>
            <td>Actions</td>
        </tr>
        </thead>
        <tbody>
        <?php foreach($query as $row): ?>
            <tr> 

            <td><?php echo $row->sales_id; ?></td>
            <td><?php echo $row->transaction_date; ?></td>
            <td><?php echo $row->product_code; ?></td>
            <td><?php echo $row->trace_number; ?></td>
            <td><?php echo $row->recipient; ?></td>
            <td><?php echo $row->is_paid; ?></td>
            <td><?php echo $row->load_balance; ?></td>
            <td><?php echo $row->c_fname . ' ' . $row->c_lname; ?></td>
            <td>
            <?php 
            echo anchor('sales/view/' . $row->sales_id, '<i class="icon-search"></i>') . ' | ' .
            anchor('sales/update/' . $row->sales_id, '<i class="icon-pencil"></i>') . ' | ' .
            anchor('#', 'Delete', 
                    array('data-confirm' => "Are you sure you want to delete?") )
            #<i class="icon-remove"></i>
            ?>
            </td>


            </tr>


        <?php endforeach; ?>
        </tbody>

    </table>

dt_header.php:

    <script type="text/javascript">
    $(document).ready(function() {
      $('a[data-confirm]').click(function(ev) {
        var href = $(this).attr('href');
        if (!$('#dataConfirmModal').length) {
          $('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="dataConfirmLabel">Please Confirm</h3></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button><a class="btn btn-primary" id="dataConfirmOK">OK</a></div></div>');
        } 
            $('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
            $('#dataConfirmOK').attr('href', href);
            $('#dataConfirmModal').modal({show:true});
        return false;
      });
    });
    </script>

当我点击锚点删除时,会显示模态。您认为我的代码有什么问题?任何帮助将得到真正的赞赏。感谢。

3 个答案:

答案 0 :(得分:1)

试试这个

<td><a class="delete" onclick="javascript:deleteConfirm('<?php echo base_url().'admin/home/delete_image/'.$image['id'];?>');" deleteConfirm href="#">Delete</a></td>

的javascript

<script type="text/javascript"> 
function deleteConfirm(url)
 {
    if(confirm('Do you want to Delete this record ?'))
    {
        window.location.href=url;
    }
 }
</script>

答案 1 :(得分:1)

试试这个

<script type="text/javascript">
    var url="<?php echo base_url();?>";
    function deleteThis(id){
       var r=confirm("Do you want to delete this?");
        if (r==true) {
          window.location = url+"user/deleteuser/"+id;
        } else {
          return false;
        }
        }

</script>
<a href="javascript:void(0);" onclick="deleteThis(<?php echo $row->id;?>);">Delete</a

答案 2 :(得分:0)

试试这个解决方案,

http://bootsnipp.com/snippets/featured/bootstrap-snipp-for-datatable

当您尝试删除内容时,

Bootstrap模式弹出。