欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

thinkPHP批量刪除的實現(xiàn)方法分析

 更新時間:2016年11月09日 09:25:14   作者:ifeixiang  
這篇文章主要介紹了thinkPHP批量刪除的實現(xiàn)方法,結(jié)合實例形式分析了thinkPHP實現(xiàn)批量刪除數(shù)據(jù)的數(shù)據(jù)庫及模板操作相關(guān)技巧,需要的朋友可以參考下

本文實例講述了thinkPHP批量刪除的實現(xiàn)方法。分享給大家供大家參考,具體如下:

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相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論