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