tableEdit.lt 917 B

12345678910111213141516171819202122232425
  1. //设置{%comment%}
  2. public function set{%funcName%}()
  3. {
  4. $id = $this->request->post('id');
  5. $fieldVal = $this->request->post('field_val');
  6. $isRecycle = $this->request->post('is_recycle');
  7. $update['{%field%}'] = $fieldVal;
  8. try {
  9. if($isRecycle) {
  10. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  11. } else {
  12. $updateRes = $this->model->where('id', '=', $id)->update($update);
  13. }
  14. if ($updateRes) {
  15. return $this->success('操作成功');
  16. } else if ($updateRes === 0) {
  17. return $this->success('未作修改');
  18. } else {
  19. return $this->error('操作失败');
  20. }
  21. } catch (\Exception $e) {
  22. return $this->error('数据库异常,操作失败');
  23. }
  24. }