手机
当前位置:查字典教程网 >编程开发 >php教程 >thinkPHP批量删除的实现方法分析
thinkPHP批量删除的实现方法分析
摘要:本文实例讲述了thinkPHP批量删除的实现方法。分享给大家供大家参考,具体如下:html:批量删除编号{$vo['id']}php:pub...

本文实例讲述了thinkPHP批量删除的实现方法。分享给大家供大家参考,具体如下:

html:

<li> <a href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel='ids' title="你确定要删除吗?" warn="请选择节点"><span>批量删除</span></a> </li> <table width="100%" layoutH="138"> <thead> <tr> <th width="10"><input type="checkbox" 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' ) ) )

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《smarty模板入门基础教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

【thinkPHP批量删除的实现方法分析】相关文章:

PHP中4种常用的抓取网络数据方法

PHP递归调用数组值并用其执行指定函数的方法

php 类自动载入的方法

php数组随机排序实现方法

多php服务器实现多session并发运行

php删除指定目录的方法

PHP正则验证Email的方法

php操作memcache缓存方法分享

php实现统计网站在线人数的方法

PHP中的流(streams)浅析

精品推荐
分类导航