zoukankan      html  css  js  c++  java
  • thinkphp批量删除的实现

    html:

    <li>
      <
    a class="delete" href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel='ids' title="你确定要删除吗?" warn="请选择节点"><span>批量删除</span></a>
    </
    li>
    <table class="table" width="100%" layoutH="138">
            <thead>
                <tr>
                    <th width="10"><input type="checkbox" class="checkboxCtrl" group="ids" /></th>
                    <th width="60">编号</th>
                </tr>
            </thead>
            <tbody>
            <volist id="vo" name="list">
                <tr>
                    <td><input name="ids" type="checkbox" value="{$vo.id}"> </td>
                    <td>{$vo['id']}</td>
                </tr>
            </volist>
    </table>

     php:

    public function deleteSelected() {
            //删除指定记录
            $name = $this->getActionName();
            $model = D($name);
            if (!empty($model)) {
                $pk = $model->getPk();
                $ids = $_REQUEST['ids'];
                if (!empty($ids)) {
                    $condition = array($pk => array('in', explode(',', $ids)));
                    if (false !== $model->where($condition)->delete()) {
                        $sql =  $model->_sql();
                        $this->success("删除成功!");
                    } else {
                        $this->error('删除失败!');
                    }
                } else {
                    $this->error('非法操作');
                }
            }

     原理是根据Web表单提交时可以传递数组,例如:

    <input type="text" name="firstname">
    <input type="text" name="lastname">
    <input type="text" name="email">
    <input type="text" name="address">
    
    <input type="text" name="tree[tree1][fruit]">
    <input type="text" name="tree[tree1][height]">
    
    <input type="text" name="tree[tree2][fruit]">
    <input type="text" name="tree[tree2][height]">
    
    <input type="text" name="tree[tree3][fruit]">
    <input type="text" name="tree[tree3][height]">
    

    则传递过来的是:

    $_POST[] = array(
        'firstname'=>'value',
        'lastname'=>'value',
        'email'=>'value',
        'address'=>'value',
        'tree' => array(
            'tree1'=>array(
                'fruit'=>'value',
                'height'=>'value'
            ),
            'tree2'=>array(
                'fruit'=>'value',
                'height'=>'value'
            ),
            'tree3'=>array(
                'fruit'=>'value',
                'height'=>'value'
            )
        )
    )
    

      

      

  • 相关阅读:
    OCS 2007 R2下载资源整理
    Windows Server 2012 R2 WSUS 4.0 加速
    JavaScript入门(三)
    JavaScript入门(一)
    JavaScript入门(二)
    CSS基础
    古董代码
    自我介绍
    Android Activity的加载的模式
    Android 数字签名
  • 原文地址:https://www.cnblogs.com/trying/p/3328110.html
Copyright © 2011-2022 走看看