/** * 更新 */ public function update($condition = '') { $this->checkRules('update'); $validateMsg = validate::getMsg(); if (empty($validateMsg)) { if (is_array($this->data)) { $data = $this->getData(); $sql = $this->implode_field_value($data); } else { $sql = $this->data; } if (empty($condition)) { $where = '1'; } elseif (is_array($condition)) { $condition = $this->getData($condition); $where = $this->implode_field_value($condition, ' AND '); } else { $where = $condition; } debug::start(); $res = $this->db->query("UPDATE {$this->pre}{$this->table} SET {$sql} WHERE {$where}"); debug::end(); debug::add("UPDATE {$this->pre}{$this->table} SET {$sql} WHERE {$where} [" . debug::spent() . "]", 1); return $res; } else { foreach ($validateMsg as $val) { debug::add("对 {$this->pre}{$this->table} 表进行更新操作时验证不通过:" . $val); } return false; } }
public function saveAction() { if (fpBase('http')->isPost()) { M($this->table)->data = $_POST; if (M($this->table)->save()) { exit(json_encode(array('statusCode' => 200, 'message' => '操作成功', 'callbackType' => 'closeCurrent'))); } else { foreach (validate::getMsg() as $val) { exit(json_encode(array('statusCode' => 300, 'message' => $val))); } exit(json_encode(array('statusCode' => 300, 'message' => '操作失败'))); } } else { $this->display(); } }