Relationmodel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\controller\example;
  3. use app\common\controller\Backend;
  4. /**
  5. * 多模型关联
  6. *
  7. * @icon fa fa-table
  8. * @remark 当使用到关联模型时需要重载index方法
  9. */
  10. class Relationmodel extends Backend
  11. {
  12. protected $model = null;
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->model = model('AdminLog');
  17. }
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. if ($this->request->isAjax())
  24. {
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. $total = $this->model
  27. ->with("Admin")
  28. ->where($where)
  29. ->order($sort, $order)
  30. ->count();
  31. $list = $this->model
  32. ->with("Admin")
  33. ->where($where)
  34. ->order($sort, $order)
  35. ->limit($offset, $limit)
  36. ->select();
  37. $result = array("total" => $total, "rows" => $list);
  38. return json($result);
  39. }
  40. return $this->view->fetch();
  41. }
  42. }