怎么在thinkPHP項目中實現(xiàn)一個批量刪除功能-創(chuàng)新互聯(lián)

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

在廣河等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網站建設、網站設計 網站設計制作按需搭建網站,公司網站建設,企業(yè)網站建設,成都品牌網站建設,成都全網營銷推廣,外貿營銷網站建設,廣河網站建設費用合理。

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('刪除失?。?#39;);
        }
      } else {
        $this->error('非法操作');
      }
    }
}

原理是根據Web表單提交時可以傳遞數組,例如:

<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'
    )
  )
)

關于怎么在thinkPHP項目中實現(xiàn)一個批量刪除功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

分享標題:怎么在thinkPHP項目中實現(xiàn)一個批量刪除功能-創(chuàng)新互聯(lián)
當前地址:http://muchs.cn/article46/dphhhg.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供品牌網站建設、軟件開發(fā)、移動網站建設、云服務器面包屑導航、動態(tài)網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網站建設