多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
add.html会将input的值转为url字符串如city_id_1=460&city_id_2=475&city_id=482&type_id=3&accessories_type_id=16&units=0&company=2&year=2021&january=&february=&march=&april=&may=&june=&july=&august=&september=&october=&november=&december=&total=&remarks= 然后在调用model的editPost方法在调用model的模型方法::update($data);执行 ``` // 添加保存 public function addPost() { if (Request::isPost()) { //Request::except(['file']获取排除指定参数后的参数数组,changeFormData查询出该表所有字段并且检测求参数是否在此字段中,不在则剔除然后根据此cms的类型改变日期等格式,然后返回 $data = MakeBuilder::changeFormData(Request::except(['file'], 'post'), $this->tableName); $result = $this->validate($data, $this->validate); if (true !== $result) { // 验证失败 输出错误信息 $this->error($result); } else { $model = '\app\common\model\\' . $this->modelName; $result = $model::addPost($data); if ($result['error']) { $this->error($result['msg']); } else { $this->success($result['msg'], 'index'); } } } } ``` ``` // model方法通用修改保存 public static function editPost($data) { try { if ($data) { foreach ($data as $k => $v) { if (is_array($v)) { $data[$k] = implode(',', $v); } } } $result = self::update($data); if ($result) { return ['error' => 0, 'msg' => '修改成功']; } else { return ['error' => 1, 'msg' => '修改失败']; } } catch (\Exception $e) { return ['error' => 1, 'msg' => $e->getMessage()]; } } ```