thinkPHP批量刪除的實(shí)現(xiàn)方法分析
本文實(shí)例講述了thinkPHP批量刪除的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
html:
<li>
<a class="delete" href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel='ids' title="你確定要?jiǎng)h除嗎?" warn="請選擇節(jié)點(diǎn)"><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">編號(hào)</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('非法操作');
}
}
}
原理是根據(jù)Web表單提交時(shí)可以傳遞數(shù)組,例如:
<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'
)
)
)
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
- ThinkPHP實(shí)現(xiàn)一鍵清除緩存方法
- ThinkPHP緩存方法S()概述
- thinkphp緩存技術(shù)詳解
- 修改ThinkPHP緩存為Memcache的方法
- Thinkphp關(guān)閉緩存的方法
- ThinkPHP靜態(tài)緩存簡單配置和使用方法詳解
- ThinkPHP實(shí)現(xiàn)靜態(tài)緩存和動(dòng)態(tài)緩存示例代碼
- ThinkPHP簡單使用memcache緩存的方法
- ThinkPHP框架中使用Memcached緩存數(shù)據(jù)的方法
- ThinkPHP實(shí)現(xiàn)批量刪除數(shù)據(jù)的代碼實(shí)例
- 基于ThinkPHP實(shí)現(xiàn)批量刪除
- TP5(thinkPHP框架)實(shí)現(xiàn)后臺(tái)清除緩存功能示例
相關(guān)文章
PHP實(shí)現(xiàn)自動(dòng)發(fā)送郵件功能代碼(qq 郵箱)
本文給大家分享以qq郵箱為例給大家介紹PHP實(shí)現(xiàn)自動(dòng)發(fā)送郵件功能代碼,感興趣的朋友參考下吧2017-08-08
PHP實(shí)現(xiàn)即時(shí)輸出、實(shí)時(shí)輸出內(nèi)容方法
這篇文章主要介紹了PHP實(shí)現(xiàn)即時(shí)輸出、實(shí)時(shí)輸出內(nèi)容方法,本文直接給出實(shí)現(xiàn)方法,需要的朋友可以參考下2015-05-05
php設(shè)計(jì)模式之代理模式分析【星際爭霸游戲案例】
這篇文章主要介紹了php設(shè)計(jì)模式之代理模式,結(jié)合星際爭霸游戲案例形式分析了PHP設(shè)計(jì)模式中代理模式的相關(guān)原理、使用方法與操作注意事項(xiàng),需要的朋友可以參考下2020-03-03
一個(gè)好用的PHP驗(yàn)證碼類實(shí)例分享
這篇文章主要介紹了一個(gè)好用的PHP驗(yàn)證碼類實(shí)例,有需要的朋友可以參考一下2013-12-12
TP5(thinkPHP5)框架使用ajax實(shí)現(xiàn)與后臺(tái)數(shù)據(jù)交互的方法小結(jié)
這篇文章主要介紹了TP5(thinkPHP5)框架使用ajax實(shí)現(xiàn)與后臺(tái)數(shù)據(jù)交互的方法,結(jié)合實(shí)例形式總結(jié)分析了thinkPHP5使用ajax與后臺(tái)數(shù)據(jù)交互的兩種實(shí)現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2020-02-02
php判斷手機(jī)瀏覽還是web瀏覽,并執(zhí)行相應(yīng)的動(dòng)作簡單實(shí)例
下面小編就為大家?guī)硪黄猵hp判斷手機(jī)瀏覽還是web瀏覽,并執(zhí)行相應(yīng)的動(dòng)作簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給的大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07

