From c132e9a4b5d0945ffcd368256f347e700842caad Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 17 Feb 2022 14:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E5=A2=9E=E5=92=8C?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=96=B9=E6=B3=95=20-=20=E5=88=86=E6=94=AF?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E6=8F=90=E5=89=8D=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/library/traits/Backend.php | 116 +++++++++---------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php index f81f62fee..d67d04a83 100755 --- a/application/admin/library/traits/Backend.php +++ b/application/admin/library/traits/Backend.php @@ -93,40 +93,39 @@ trait Backend { if ($this->request->isPost()) { $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); + if (!$params) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); - if ($this->dataLimit && $this->dataLimitFieldAutoFill) { - $params[$this->dataLimitField] = $this->auth->id; - } - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; - $this->model->validateFailException(true)->validate($validate); - } - $result = $this->model->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were inserted')); + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException(true)->validate($validate); } + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); } - $this->error(__('Parameter %s can not be empty', '')); + $this->success(); } return $this->view->fetch(); } @@ -148,36 +147,35 @@ trait Backend } if ($this->request->isPost()) { $params = $this->request->post("row/a"); - if ($params) { - $params = $this->preExcludeFields($params); - $result = false; - Db::startTrans(); - try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; - $row->validateFailException(true)->validate($validate); - } - $result = $row->allowField(true)->save($params); - Db::commit(); - } catch (ValidateException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (PDOException $e) { - Db::rollback(); - $this->error($e->getMessage()); - } catch (Exception $e) { - Db::rollback(); - $this->error($e->getMessage()); - } - if ($result !== false) { - $this->success(); - } else { - $this->error(__('No rows were updated')); + if (!$params) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException(true)->validate($validate); } + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); } - $this->error(__('Parameter %s can not be empty', '')); + if ($result === false) { + $this->error(__('No rows were updated')); + } + $this->success(); } $this->view->assign("row", $row); return $this->view->fetch(); -- Gitee