基于ThinkPHP實(shí)現(xiàn)批量刪除
本文實(shí)例分析了基于ThinkPHP實(shí)現(xiàn)批量刪除的代碼實(shí)例,分享給大家供大家參考,具體如下:
廢話不多說(shuō),先上效果圖:

HTML布局(基于bootstrap)
<div class="panel panel-default">
<div class="panel-heading">
留言列表
<a class="btn btn-xs btn-default pull-right" href="javascript:window.history.back();">返回</a>
<a class="btn btn-xs btn-info pull-right mr-5" id="discard" href="javascript:;">刪除</a>
</div>
<table class="table">
<thead>
<tr>
<th><input class="all" type="checkbox"/></th>
<th>id</th>
<th>名稱</th>
<th>郵箱</th>
<th>內(nèi)容</th>
<th>日期時(shí)間</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<form>
<volist name="list" id="vo" empty="$empty">
<tr>
<td><input name="delete[]" type="checkbox" value="{$vo.id}" /></td>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>{$vo.email}</td>
<td>{$vo.subject}</td>
<td>{$vo.datetime|date="Y-m-d H:i", ###}</td>
<td>
<a class="delete" href="javascript:;" data-id="{$vo.id}">刪除</a>
</td>
</tr>
</volist>
</form>
</tbody>
</table>
</div>
JS腳本處理(使用ajax技術(shù))
首先判斷有沒(méi)有選中的值,如果沒(méi)有則提示;如果有,則傳遞到服務(wù)器端處理
/* 批量刪除 */
// 全選
$('.all').click(function() {
if($(this).is(':checked')) {
$(':checkbox').attr('checked', 'checked');
} else {
$(':checkbox').removeAttr('checked');
}
});
// 刪除操作
$('#discard').click(function() {
if($(':checked').size() > 0) {
layer.confirm('確定要?jiǎng)h除嗎?', {
btn: ['確定','取消'], //按鈕
shade: false //不顯示遮罩
}, function(){
$.post("{:U('Single/discard')}", {data: $('form').serializeArray()}, function(res) {
if(res.state == 1) {
layer.msg(res.message, {icon: 1, time: 1000});
} else {
layer.msg(res.message, {icon: 2, time: 1000});
}
setTimeout(function() {
location.reload();
}, 1000);
});
}, function(){
layer.msg('取消了刪除!', {time: 1000});
});
} else {
layer.alert('沒(méi)有選擇!');
}
});
PHP代碼:
獲取提交的數(shù)據(jù),然后循環(huán)得到每一個(gè)id的值,接著進(jìn)行刪除操作。
public function discard() {
$contact = M('contact');
$deleteArr = I('post.data');
for($i=0;$i<count($deleteArr);$i++) {
$contact->delete($deleteArr[$i]['value']);
}
$this->ajaxReturn(array('message'=>'刪除成功!'));
}
以上就是ThinkPHP實(shí)現(xiàn)批量刪除的關(guān)鍵性代碼,希望對(duì)大家的學(xué)習(xí)有所幫助。
- ThinkPHP實(shí)現(xiàn)一鍵清除緩存方法
- ThinkPHP緩存方法S()概述
- thinkphp緩存技術(shù)詳解
- 修改ThinkPHP緩存為Memcache的方法
- Thinkphp關(guān)閉緩存的方法
- ThinkPHP靜態(tài)緩存簡(jiǎn)單配置和使用方法詳解
- ThinkPHP實(shí)現(xiàn)靜態(tài)緩存和動(dòng)態(tài)緩存示例代碼
- ThinkPHP簡(jiǎn)單使用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)數(shù)組去重的方法詳解
這篇文章主要介紹了PHP編程快速實(shí)現(xiàn)數(shù)組去重的方法,結(jié)合實(shí)例形式分析了php數(shù)組去重復(fù)函數(shù)與使用技巧,需要的朋友可以參考下2017-07-07
ThinkPHP中使用ajax接收json數(shù)據(jù)的方法
在ThinkPHP框架中,使用AJAX接收J(rèn)SON數(shù)據(jù)通常涉及前端和后端的交互,前端通過(guò)AJAX發(fā)送JSON數(shù)據(jù)到后端,后端控制器接收并處理這些數(shù)據(jù),然后可能返回一些響應(yīng)數(shù)據(jù),本文給大家介紹了ThinkPHP中使用ajax接收json數(shù)據(jù)的方法,需要的朋友可以參考下2024-11-11
PHP識(shí)別二維碼的方法(php-zbarcode安裝與使用)
這篇文章主要介紹了PHP識(shí)別二維碼的方法,通過(guò)安裝ImageMagick和php-zbarcode擴(kuò)展實(shí)現(xiàn)針對(duì)二維碼的識(shí)別功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
解析PHP中的file_get_contents獲取遠(yuǎn)程頁(yè)面亂碼的問(wèn)題
本篇文章是對(duì)PHP中的file_get_contents獲取遠(yuǎn)程頁(yè)面出現(xiàn)亂碼的問(wèn)題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
有關(guān)于PHP中常見(jiàn)數(shù)據(jù)類型的匯總分享
本文整理了有關(guān)于PHP中常見(jiàn)的數(shù)據(jù)類型,感興趣的朋友可以參考下2014-01-01

