Diyform.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 $searchFields = 'id,name,title,table';
  16. protected $noNeedRight = ['check_element_available'];
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $config = get_addon_config('cms');
  21. if ($config['diyformdatalimit'] != 'all') {
  22. $this->dataLimit = $config['diyformdatalimit'];
  23. }
  24. $this->assignconfig('spiderRecord', intval($config['spiderrecord']?? 0));
  25. $this->model = new \app\admin\model\cms\Diyform;
  26. $this->view->assign("statusList", $this->model->getStatusList());
  27. }
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags', 'trim']);
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $list = $this->model
  42. ->where($where)
  43. ->order($sort, $order)
  44. ->paginate($limit);
  45. \app\admin\model\cms\SpiderLog::render($list, 'diyform');
  46. $result = array("total" => $list->total(), "rows" => $list->items());
  47. return json($result);
  48. }
  49. return $this->view->fetch();
  50. }
  51. /**
  52. * 检测元素是否可用
  53. * @internal
  54. */
  55. public function check_element_available()
  56. {
  57. $id = $this->request->request('id');
  58. $name = $this->request->request('name');
  59. $value = $this->request->request('value');
  60. $name = substr($name, 4, -1);
  61. if (!$name) {
  62. $this->error(__('Parameter %s can not be empty', 'name'));
  63. }
  64. if ($id) {
  65. $this->model->where('id', '<>', $id);
  66. }
  67. $exist = $this->model->where($name, $value)->find();
  68. if ($exist) {
  69. $this->error(__('The data already exist'));
  70. } else {
  71. $this->success();
  72. }
  73. }
  74. }