搜索
首页php教程php手册thinkPHP如何实现批量删除的效果

thinkPHP如何实现批量删除的效果

Jun 13, 2016 am 10:37 AM
thinkphp批量删除

这篇文章主要介绍了thinkPHP批量删除的实现方法,结合实例形式分析了thinkPHP实现批量删除数据的数据库及模板操作相关技巧,需要的朋友可以参考下

html部分:

<li>
  <a class="delete" href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel=&#39;ids&#39; 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[&#39;id&#39;]}</td>
      </tr>
    </volist>
</table>

php部分:

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

原理是根据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(
  &#39;firstname&#39;=>&#39;value&#39;,
  &#39;lastname&#39;=>&#39;value&#39;,
  &#39;email&#39;=>&#39;value&#39;,
  &#39;address&#39;=>&#39;value&#39;,
  &#39;tree&#39; => array(
    &#39;tree1&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    ),
    &#39;tree2&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    ),
    &#39;tree3&#39;=>array(
      &#39;fruit&#39;=>&#39;value&#39;,
      &#39;height&#39;=>&#39;value&#39;
    )
  )
)

【相关教程推荐】

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境