Zone.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\controller\ask;
  3. use app\common\controller\Backend;
  4. /**
  5. * 问答专区管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Zone extends Backend
  10. {
  11. /**
  12. * Zone模型对象
  13. * @var \app\admin\model\ask\Zone
  14. */
  15. protected $model = null;
  16. protected $multiFields = 'status,isnav';
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\ask\Zone;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 添加
  30. */
  31. public function add()
  32. {
  33. $this->view->assign("condition", [
  34. 'level' => 0,
  35. 'score' => 0,
  36. 'isexpert' => 0,
  37. 'joindays' => 0,
  38. ]);
  39. return parent::add();
  40. }
  41. /**
  42. * 检测元素是否可用
  43. * @internal
  44. */
  45. public function check_element_available()
  46. {
  47. $id = $this->request->request('id');
  48. $name = $this->request->request('name');
  49. $value = $this->request->request('value');
  50. $name = substr($name, 4, -1);
  51. if (!$name) {
  52. $this->error(__('Parameter %s can not be empty', 'name'));
  53. }
  54. if ($id) {
  55. $this->model->where('id', '<>', $id);
  56. }
  57. $exist = $this->model->where($name, $value)->find();
  58. if ($exist) {
  59. $this->error(__('The data already exist'));
  60. } else {
  61. $this->success();
  62. }
  63. }
  64. }