Relationmodel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. $this->relationSearch = true;
  24. $this->searchFields = "admin.username,id";
  25. if ($this->request->isAjax())
  26. {
  27. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  28. $total = $this->model
  29. ->with("admin")
  30. ->where($where)
  31. ->order($sort, $order)
  32. ->count();
  33. $list = $this->model
  34. ->with("admin")
  35. ->where($where)
  36. ->order($sort, $order)
  37. ->limit($offset, $limit)
  38. ->select();
  39. $result = array("total" => $total, "rows" => $list);
  40. return json($result);
  41. }
  42. return $this->view->fetch();
  43. }
  44. }