這篇文章給大家介紹怎么在thinkPHP項(xiàng)目中實(shí)現(xiàn)一個(gè)批量刪除功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

html:
<li>
<a class="delete" href="__URL__/deleteSelected/navTabId/__MODULE__" target="selectedTodo" posttype="string" calback="navTabAjaxMenu" rel='ids' title="你確定要?jiǎng)h除嗎?" warn="請(qǐng)選擇節(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]">
則傳遞過(guò)來(lái)的是:
$_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項(xiàng)目中實(shí)現(xiàn)一個(gè)批量刪除功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享標(biāo)題:怎么在thinkPHP項(xiàng)目中實(shí)現(xiàn)一個(gè)批量刪除功能-創(chuàng)新互聯(lián)
當(dāng)前地址:http://chinadenli.net/article46/dphhhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、軟件開(kāi)發(fā)、移動(dòng)網(wǎng)站建設(shè)、云服務(wù)器、面包屑導(dǎo)航、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容