0
0

SysArticle.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\controller;
  3. class SysArticle extends Auth
  4. {
  5. public function index(){
  6. if(request()->isAjax()){
  7. //分页参数
  8. $length = input('rows',10,'intval'); //每页条数
  9. $page = input('page',1,'intval'); //第几页
  10. $start = ($page - 1) * $length; //分页开始位置
  11. //排序
  12. $sortRow = input('sidx','id','trim'); //排序列
  13. $sort = input('sord','desc','trim'); //排序方式
  14. $order = $sortRow.' '.$sort;
  15. $map= empty($map) ? true: $map;
  16. //数据查询
  17. $lists = db('sys_article')->limit($start,$length)->where($map)->order($order)->select();
  18. //数据返回
  19. $totalCount = db('sys_article')->where($map)->count();
  20. $totalPage = ceil($totalCount/$length);
  21. $result['page'] = $page;
  22. $result['total'] = $totalPage;
  23. $result['records'] = $totalCount;
  24. $result['rows'] = $lists;
  25. return json($result);
  26. }else{
  27. return $this->fetch();
  28. }
  29. }
  30. /**
  31. * 新增/编辑
  32. */
  33. public function add($id=0){
  34. if(request()->isPost()){
  35. $res = model('SysArticle')->updates();
  36. if($res){
  37. $this->success('操作成功',url('index'));
  38. }else{
  39. $this->error(model('SysArticle')->getError());
  40. }
  41. }else{
  42. $title = '新增';
  43. if($id){
  44. $title = '编辑';
  45. $info = db('sys_article')->where('id',$id)->find();
  46. $this->assign('info',$info);
  47. }
  48. $this->assign('title',$title);
  49. return $this->fetch();
  50. }
  51. }
  52. }