Thinkphp add addAll
add用户添加一条数据。项目实例 public function treeinsert(){ $data=array(); $data['id']=''; $data['type']='0'; $data['title']=$_REQUEST['name']; $data['level']=$_REQUEST['level']; $data['pid']=$_REQUEST['ids']; $data['sort']='0'; $data['status']='1'; $data['rules']=''; $data['Mome']=''; $data['remarks']=''; $user=M('worktelgroup'); $user->add($data); } addAll是往数据库中同时添加多条数据,数据为二维数组、同时二维数组的键由0开始,项目实例: public function telnode(){ $itemid = I('post.itemid'); $data=I('post.data'); $insert=array(); foreach ($data as $k => $v) { $insert[$k]['id']=''; $insert[$k]['wtelid']=str_replace('s', '', $v['id']); $insert[$k]['itemid']=$itemid; } //var_dump($insert); $user=M('item_worktel'); $user->addAll($insert); } 组成的$insert数据结构如下: array(2) { [0]=> array(3) { ["id"]=> string(0) "" ["wtelid"]=> string(1) "2" ["itemid"]=> string(1) "9" } [1]=> array(3) { ["id"]=> string(0) "" ["wtelid"]=> string(2) "11" ["itemid"]=> string(1) "9" } }