Multitable.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ->field('id,filename,filesize,imagewidth,imageheight,mimetype')
  41. ->order($sort, $order)
  42. ->count();
  43. $list = $this->model
  44. ->where($where)
  45. ->field('id,filename,filesize,imagewidth,imageheight,mimetype')
  46. ->order($sort, $order)
  47. ->limit($offset, $limit)
  48. ->select();
  49. $result = array("total" => $total, "rows" => $list);
  50. return json($result);
  51. }
  52. return $this->view->fetch('index');
  53. }
  54. public function table2()
  55. {
  56. $this->model = model('AdminLog');
  57. //设置过滤方法
  58. $this->request->filter(['strip_tags']);
  59. if ($this->request->isAjax()) {
  60. //如果发送的来源是Selectpage,则转发到Selectpage
  61. if ($this->request->request('keyField')) {
  62. return $this->selectpage();
  63. }
  64. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  65. $total = $this->model
  66. ->where($where)
  67. ->order($sort, $order)
  68. ->count();
  69. $list = $this->model
  70. ->where($where)
  71. ->order($sort, $order)
  72. ->limit($offset, $limit)
  73. ->select();
  74. $result = array("total" => $total, "rows" => $list);
  75. return json($result);
  76. }
  77. return $this->view->fetch('index');
  78. }
  79. }