|
@@ -36,6 +36,46 @@ class Team extends Backend |
|
@@ -36,6 +36,46 @@ class Team extends Backend |
36
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
36
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
37
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
37
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
38
|
*/
|
38
|
*/
|
|
|
39
|
+ /**
|
|
|
40
|
+ * 添加
|
|
|
41
|
+ *
|
|
|
42
|
+ * @return string
|
|
|
43
|
+ * @throws \think\Exception
|
|
|
44
|
+ */
|
|
|
45
|
+ public function add()
|
|
|
46
|
+ {
|
|
|
47
|
+ if (false === $this->request->isPost()) {
|
|
|
48
|
+ return $this->view->fetch();
|
|
|
49
|
+ }
|
|
|
50
|
+ $params = $this->request->post('row/a');
|
|
|
51
|
+ if (empty($params)) {
|
|
|
52
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
53
|
+ }
|
|
|
54
|
+ $params = $this->preExcludeFields($params);
|
|
|
55
|
+
|
|
|
56
|
+ if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
57
|
+ $params[$this->dataLimitField] = $this->auth->id;
|
|
|
58
|
+ }
|
|
|
59
|
+ $result = false;
|
|
|
60
|
+ Db::startTrans();
|
|
|
61
|
+ try {
|
|
|
62
|
+ //是否采用模型验证
|
|
|
63
|
+ if ($this->modelValidate) {
|
|
|
64
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
65
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
66
|
+ $this->model->validateFailException()->validate($validate);
|
|
|
67
|
+ }
|
|
|
68
|
+ $result = $this->model->allowField(true)->save($params);
|
|
|
69
|
+ Db::commit();
|
|
|
70
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
71
|
+ Db::rollback();
|
|
|
72
|
+ $this->error($e->getMessage());
|
|
|
73
|
+ }
|
|
|
74
|
+ if ($result === false) {
|
|
|
75
|
+ $this->error(__('No rows were inserted'));
|
|
|
76
|
+ }
|
|
|
77
|
+ $this->success();
|
|
|
78
|
+ }
|
39
|
|
79
|
|
40
|
/**
|
80
|
/**
|
41
|
* 编辑
|
81
|
* 编辑
|