Multitable.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\admin\controller\example;
  3. use app\common\controller\Backend;
  4. /**
  5. * 多表格示例
  6. *
  7. * @icon fa fa-table
  8. * @remark 当一个页面上存在多个Bootstrap-table时该如何控制按钮和表格
  9. */
  10. class Multitable extends Backend
  11. {
  12. protected $model = null;
  13. protected $noNeedRight = ['table1', 'table2'];
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. }
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. $this->loadlang('general/attachment');
  24. $this->loadlang('general/crontab');
  25. return $this->view->fetch();
  26. }
  27. public function table1()
  28. {
  29. $this->model = model('Attachment');
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags']);
  32. if ($this->request->isAjax()) {
  33. //如果发送的来源是Selectpage,则转发到Selectpage
  34. if ($this->request->request('keyField')) {
  35. return $this->selectpage();
  36. }
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  38. $total = $this->model
  39. ->where($where)
  40. ->order($sort, $order)
  41. ->count();
  42. $list = $this->model
  43. ->where($where)
  44. ->order($sort, $order)
  45. ->limit($offset, $limit)
  46. ->select();
  47. $result = array("total" => $total, "rows" => $list);
  48. return json($result);
  49. }
  50. return $this->view->fetch('index');
  51. }
  52. public function table2()
  53. {
  54. $this->model = model('AdminLog');
  55. //设置过滤方法
  56. $this->request->filter(['strip_tags']);
  57. if ($this->request->isAjax()) {
  58. //如果发送的来源是Selectpage,则转发到Selectpage
  59. if ($this->request->request('keyField')) {
  60. return $this->selectpage();
  61. }
  62. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  63. $total = $this->model
  64. ->where($where)
  65. ->order($sort, $order)
  66. ->count();
  67. $list = $this->model
  68. ->where($where)
  69. ->order($sort, $order)
  70. ->limit($offset, $limit)
  71. ->select();
  72. $result = array("total" => $total, "rows" => $list);
  73. return json($result);
  74. }
  75. return $this->view->fetch('index');
  76. }
  77. }