/** * 添加记录 * return lastid */ function insert($pData, $pReplace = false) { if ($this->_filter($pData)) { $tField = '`' . join('`,`', array_keys($pData)) . '`'; $tVal = join("','", $pData); //echo ($pReplace? "REPLACE": "INSERT") . " INTO `$this->table`($tField) VALUES ('$tVal')"; if ($this->exec(($pReplace ? "REPLACE" : "INSERT") . " INTO {$this->table}({$tField}) VALUES ('{$tVal}')")) { return $this->db->lastInsertId(); } } return 0; }
/** * 添加类别 * * @param array $data 类别信息数组 */ public function add(array $data) { $node['cate_name'] = $data['cate_name']; $node['parent_id'] = $data['parent_id']; $node['sort_order'] = $data['sort_order']; $node['is_show'] = $data['is_show']; if (!empty($data['cate_id'])) { // 导入数据需要设定id $node['cate_id'] = $data['cate_id']; } $this->db->insert('category', $node); $lastId = $this->db->lastInsertId(); // 更新路径信息 $path = $this->getPath($node['parent_id']) . "{$lastId};"; $where = $this->db->quoteInto('cate_id = ?', $lastId); $this->db->update('category', array('path' => $path), $where); $this->_allCates = null; }