作者 王智

daima

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
  5 +use think\Db;
5 use app\common\controller\Backend; 6 use app\common\controller\Backend;
6 7
7 /** 8 /**
@@ -74,4 +75,59 @@ class Renwu extends Backend @@ -74,4 +75,59 @@ class Renwu extends Backend
74 } 75 }
75 return $this->view->fetch(); 76 return $this->view->fetch();
76 } 77 }
  78 +
  79 +
  80 + /**
  81 + * 编辑
  82 + */
  83 + public function edit($ids = null)
  84 + {
  85 + $row = $this->model->get($ids);
  86 + dump($row);
  87 + die;
  88 + if (!$row) {
  89 + $this->error(__('No Results were found'));
  90 + }
  91 + $adminIds = $this->getDataLimitAdminIds();
  92 + if (is_array($adminIds)) {
  93 + if (!in_array($row[$this->dataLimitField], $adminIds)) {
  94 + $this->error(__('You have no permission'));
  95 + }
  96 + }
  97 + if ($this->request->isPost()) {
  98 + $params = $this->request->post("row/a");
  99 + if ($params) {
  100 + $params = $this->preExcludeFields($params);
  101 + $result = false;
  102 + Db::startTrans();
  103 + try {
  104 + //是否采用模型验证
  105 + if ($this->modelValidate) {
  106 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  107 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  108 + $row->validateFailException(true)->validate($validate);
  109 + }
  110 + $result = $row->allowField(true)->save($params);
  111 + Db::commit();
  112 + } catch (ValidateException $e) {
  113 + Db::rollback();
  114 + $this->error($e->getMessage());
  115 + } catch (PDOException $e) {
  116 + Db::rollback();
  117 + $this->error($e->getMessage());
  118 + } catch (Exception $e) {
  119 + Db::rollback();
  120 + $this->error($e->getMessage());
  121 + }
  122 + if ($result !== false) {
  123 + $this->success();
  124 + } else {
  125 + $this->error(__('No rows were updated'));
  126 + }
  127 + }
  128 + $this->error(__('Parameter %s can not be empty', ''));
  129 + }
  130 + $this->view->assign("row", $row);
  131 + return $this->view->fetch();
  132 + }
77 } 133 }