Diyform.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. /**
  5. * 自定义表单表
  6. *
  7. * @icon fa fa-list
  8. */
  9. class Diyform extends Backend
  10. {
  11. /**
  12. * Model模型对象
  13. */
  14. protected $model = null;
  15. protected $noNeedRight = ['check_element_available'];
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $cms = get_addon_config('cms');
  20. if ($cms['diyformdatalimit'] != 'all') {
  21. $this->dataLimit = $cms['diyformdatalimit'];
  22. }
  23. $this->model = new \app\admin\model\cms\Diyform;
  24. $this->view->assign("statusList", $this->model->getStatusList());
  25. }
  26. /**
  27. * 检测元素是否可用
  28. * @internal
  29. */
  30. public function check_element_available()
  31. {
  32. $id = $this->request->request('id');
  33. $name = $this->request->request('name');
  34. $value = $this->request->request('value');
  35. $name = substr($name, 4, -1);
  36. if (!$name) {
  37. $this->error(__('Parameter %s can not be empty', 'name'));
  38. }
  39. if ($id) {
  40. $this->model->where('id', '<>', $id);
  41. }
  42. $exist = $this->model->where($name, $value)->find();
  43. if ($exist) {
  44. $this->error(__('The data already exist'));
  45. } else {
  46. $this->success();
  47. }
  48. }
  49. }