今天在修改一個(gè)網(wǎng)站的時(shí)候,發(fā)現(xiàn)原來的數(shù)據(jù)庫中內(nèi)鏈數(shù)量太多了,以至于要?jiǎng)h除就得一個(gè)一個(gè)刪除,我一共35條內(nèi)鏈,就刪了35次之多。累人。為什么不搞一個(gè)批量刪除呢。
下面我們自己來動(dòng)手進(jìn)行修改:
弟一步:打開模板文件:tags.html
在第十行左右的
<table class="layui-table">
上面增加以下代碼
<form action="{url./admin/Tags/del}" method="post" id="contentForm" name="contentForm" class="layui-form" onkeydown="if(event.keyCode==13) return false;"> <input type="hidden" name="formcheck" value="{$formcheck}" >
在
<th>序號(hào)</th>
上面添加:
<th width="10"><input type="checkbox" class="checkbox" lay-ignore id="checkall" title="全選"></th>
在
{foreach $tags(key,value)} <tr>
下面添加:
<td><input type="checkbox" class="checkbox checkitem" lay-ignore name="list[]" value="[value->id]" id="checka"></td>
然后在這個(gè)table結(jié)束的地方增加以下代碼
<div class="layui-btn-group"> <button type="submit" name="submit" onclick="return setDelAction();" class="layui-btn layui-btn-sm">批量刪除</button> {if([$messages])} {/if} </div> </form> <script> function setDelAction(){ document.contentForm.action = "{url./admin/Tags/del}"; return confirm("您確定要?jiǎng)h除選中的內(nèi)容么?"); } </script>
第二步:打開控制器,找到:TagsController.php
找到文章刪除的函數(shù):
// 文章內(nèi)鏈刪除 public function del()
然后在函數(shù)里面添加以下代碼
// 執(zhí)行批量刪除 if ($_POST) { if (! ! $list = post('list')) { if ($this->model->delTagsList($list)) { $this->log('批量刪除留言成功!'); success('批量刪除成功!', - 1); } else { $this->log('批量刪除留言失??!'); error('批量刪除失??!', - 1); } } else { alert_back('請(qǐng)選擇要?jiǎng)h除的內(nèi)容!'); } }
第三步:找到模型中的:TagsModel.php
在55行左右的刪除文章內(nèi)鏈函數(shù)結(jié)束添加以下函數(shù)
// 批量刪除 public function delTagsList($ids) { return parent::table('ay_tags')->where("acode='" . session('acode') . "'") ->delete($ids); }
至此,功能制作完成。
有關(guān)我們服務(wù)的更多信息,請(qǐng)聯(lián)系項(xiàng)目經(jīng)理
15899750475 楊先生