controllerindex.stub 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * 查看
  3. */
  4. public function index()
  5. {
  6. //当前是否为关联查询
  7. $this->relationSearch = {%relationSearch%};
  8. //设置过滤方法
  9. $this->request->filter(['strip_tags', 'trim']);
  10. if ($this->request->isAjax())
  11. {
  12. //如果发送的来源是Selectpage,则转发到Selectpage
  13. if ($this->request->request('keyField'))
  14. {
  15. return $this->selectpage();
  16. }
  17. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  18. $total = $this->model
  19. {%relationWithList%}
  20. ->where($where)
  21. ->order($sort, $order)
  22. ->count();
  23. $list = $this->model
  24. {%relationWithList%}
  25. ->where($where)
  26. ->order($sort, $order)
  27. ->limit($offset, $limit)
  28. ->select();
  29. foreach ($list as $row) {
  30. {%visibleFieldList%}
  31. {%relationVisibleFieldList%}
  32. }
  33. $list = collection($list)->toArray();
  34. $result = array("total" => $total, "rows" => $list);
  35. return json($result);
  36. }
  37. return $this->view->fetch();
  38. }