Lists.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\admin\controller\news;
  3. use app\common\controller\Backend;
  4. /**
  5. * 信息列管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Lists extends Backend
  10. {
  11. /**
  12. * Lists模型对象
  13. * @var \app\admin\model\news\Lists
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\common\model\Lists;
  20. }
  21. /**
  22. * 查看
  23. *
  24. * @return string|Json
  25. * @throws \think\Exception
  26. * @throws DbException
  27. */
  28. public function index()
  29. {
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags', 'trim']);
  32. if (false === $this->request->isAjax()) {
  33. return $this->view->fetch();
  34. }
  35. //如果发送的来源是 Selectpage,则转发到 Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  40. $list = $this->model->with('types')
  41. ->where($where)
  42. ->order($sort, $order)
  43. ->paginate($limit);
  44. $result = ['total' => $list->total(), 'rows' => $list->items()];
  45. return json($result);
  46. }
  47. }