You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use DB;
  5. class CommonController extends Controller
  6. {
  7. public $user_info;
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. if(isset($_SESSION['admin_user_info']))
  12. {
  13. $this->user_info = $_SESSION['admin_user_info'];
  14. }
  15. else
  16. {
  17. header("Location:".route('page404'));
  18. exit();
  19. }
  20. }
  21. /**
  22. * 获取分页数据及分页导航
  23. * @param string $modelname 模块名与数据库表名对应
  24. * @param array $map 查询条件
  25. * @param string $orderby 查询排序
  26. * @param string $field 要返回数据的字段
  27. * @param int $listRows 每页数量,默认10条
  28. *
  29. * @return 格式化后输出的数据。内容格式为:
  30. * - "code" (string):代码
  31. * - "info" (string):信息提示
  32. *
  33. * - "result" array
  34. *
  35. * - "img_list" (array) :图片队列,默认8张
  36. * - "img_title" (string):车图名称
  37. * - "img_url" (string):车图片url地址
  38. * - "car_name" (string):车名称
  39. */
  40. public function pageList($modelname, $map = '', $orderby = '', $field = '', $listRows = 15)
  41. {
  42. $orderby = !empty($orderby) ? $orderby : $orderby = ['id', 'desc'];
  43. // 查询满足的数据,并且每页显示15条数据
  44. $voList = DB::table($modelname)->where($map)->orderBy($orderby[0], $orderby[1])->paginate($listRows);
  45. return $voList;
  46. }
  47. }