CI删除id传递

public.js

删除的js

------------

//>>获取对象类
function getObj(id){
  var obj = document.getElementById(id);
 
  if (obj)
  {
    return obj;
  }
 
  obj = document.getElementsByName(id);
 
  if (obj.length){
    return obj[0];
  }else{
      return null;
   }
   
}

function getObjs(name){  
  return document.getElementsByName(name);   
}

//通用checkbox类
function checkbox_all(name, checked, flush)
{//根据checked确定name checkbox的 checded值
//提供flush=1时,用于获取选中的项目放到数组中,给其它fun用
  var objs = getObjs(name);
  window.checkbox_ids = [];
 
  if (!objs || !objs.length) return 0;//alert("<input type=checkbox name=" + name + ">对象不存在");
 
  for (var for_i = 0; for_i < objs.length; for_i++)
  {
    if ( (objs[for_i].tagName != 'INPUT') || (objs[for_i].type != 'checkbox') )
    {
      alert('第' + (for_i+1) + '个name=' + name + '对象,tagName为' + objs[for_i].tagName + ',type为' + objs[for_i].type + ';因此对象不是checkbox略过.');
    }else
    {
      if (!flush) objs[for_i].checked = checked;
      
      if ( (!flush && checked) || (flush && objs[for_i].checked) ) window.checkbox_ids[window.checkbox_ids.length] = objs[for_i].value;
    }
  }
}


function delAll(ctr, name) {
  if (! site_url)return alert('请指定site_url');
  if (!ctr) return alert('请指定控制器');
  if (!name)name = 'id[]';
  checkbox_all(name, 0, 1);
  if (! window.checkbox_ids || ! window.checkbox_ids.length) return alert('请选择列表');

        if(confirm("删除后将无法恢复数据,是否真的要删除如后ID的记录:" + window.checkbox_ids.join(',') )) {
            location.href = site_url + 'index.php/' + ctr + "/del" + window.checkbox_ids.join('_');
        }
}
//<<<<<

------------------

view/del.php

----------

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>系统日志</title>
<?php echo link_tag('styles/screen.css'); ?>
<?php echo link_tag('test/styles/main.css'); ?>
</head>
<body>
<div id="bodyDiv">
 
  <fieldset>
    <legend>系统日志</legend>
    <?php if (isset($tip)){ echo '<div style="color:red;">' .$tip. '</div>'; } ?>
    <table class="listTable" >
    <tr>
      <th>
      <input  οnclick="checkbox_all('id[]', this.checked)" type="checkbox" />
      Id</th>
      <th>日志内容</th>
      <th>生成时间</th>
    </tr>
    
    <?php
    
    foreach( $lists as $list){
      echo "
      <tr>
        <td>
        <input type=checkbox name=id[] value={$list['id']} />
        {$list['id']}</td>
        <td>" .htmlspecialchars($list['log']). "</td>
        <td>" .date('Y-m-d H:I:s', $list['time']). "</td>
      </tr>
      ";
    }
    ?>
    
    <tr>
      <td >
        <input type="button" value="删除" οnclick="delAll('test/init/del/1')" />
      </td>
      <td colspan=2>
      <?php echo $pageCode; ?>
      </td>
    </tr>
    
    </table>
    
    
  </fieldset>
</div>
</body>
</html>
<script>var site_url = '<?php echo base_url();?>'; </script>
<?php echo scriptSrc('scripts/public.js'); ?>

----------------

ctrollers/del.php

--------

/**
     *系统日记
     */
    public function sys_log(){
        $del = $this->uri->segment(5, '');
        
        if (FALSE !== strpos($del, 'del')){//删除
            $del = str_replace('del', '', $del);
            $del = explode('_', $del);
            
            if ( empty($del)){
                $data['tip'] = '错误id';
            }else{
                $this->db->where_in('id', $del);
                $this->db->delete('sys_log');
                $data['tip'] = '删除完成:' .implode(',', $del);
            }
        }

分页显示代码.......

--------

效果

--------

CI删除id传递 - qidizi - qidizi 的博客

因为不像&del=id这样的形式,所以这样处理时可以防止这节放其它参数,如页码时也当删除id,删除了记录情况

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值