這篇文章主要介紹了thinkPHP批量刪除的實現方法,結合實例形式分析了thinkPHP實現批量刪除數據的數據庫及模板操作相關技巧,需要的朋友可以參考下
本文實例講述了thinkPHP批量刪除的實作方法。分享給大家參考,具體如下:
html:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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表單提交時可以傳遞數組,例如:
#
1 2 3 4 5 6 7 8 9 10 | <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]">
|
登入後複製
則傳遞過來的是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $_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'
)
)
)
|
登入後複製
以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!
相關推薦:
基於Thinkphp和jquery 實作ajax多重選取不選不選刪除資料的功能
##關於thinkphp框架實作刪除和批次刪除的分析
用ThinkPHP框架實作使用者資訊查詢以及更新刪除的功能
##
以上是關於thinkPHP實作批量刪除的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!