MBaseController.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Common\Controller;
  3. use Think\Controller;
  4. /**
  5. * 官网M站点的baseController
  6. * Class MBaseController
  7. * @package Common\Controller
  8. */
  9. class MBaseController extends Controller
  10. {
  11. public function __construct() {
  12. parent::__construct();
  13. $this->set_ad_message_cookie();
  14. $regular_server = new \Common\Server\RegularServer();
  15. $is_mobile = $regular_server->is_mobile_request();
  16. if (!$is_mobile == true) {
  17. $url = U('/index/index', array(),true, true);
  18. // $url = 'http://www.x-motion.cn/about/join/';
  19. header('Location: ' . $url);
  20. die;
  21. }
  22. }
  23. public function _empty() {
  24. header("Location:" . U('/m', '', true, true));
  25. die;
  26. }
  27. /**
  28. * 设置广告来源缓存
  29. * @author: linch
  30. */
  31. private function set_ad_message_cookie() {
  32. $ad_code_name = \Common\Model\AdMessageModel::ad_code_name;
  33. $code = trim(I('get.' . $ad_code_name, ''));
  34. if (!empty($code)) {
  35. cookie($ad_code_name, $code);
  36. }
  37. }
  38. /**
  39. * 获取分页
  40. * @author: linch
  41. * @param $count
  42. * @param $page_size
  43. * @param $page_num
  44. * @param array $param
  45. * @return array
  46. */
  47. public function get_page($count, $page_size, $page_num, $param = array()){
  48. $page_count = ceil($count / $page_size);
  49. $page = array(
  50. 'pre' => 0,
  51. 'next' => 0,
  52. );
  53. if ($page_num > 1) {
  54. $param['p'] = $page_num - 1;
  55. $page['pre'] = U(CONTROLLER_NAME . '/' . ACTION_NAME, $param);
  56. }
  57. if ($page_num < $page_count) {
  58. $param['p'] = $page_num + 1;
  59. $page['next'] = U(CONTROLLER_NAME . '/' . ACTION_NAME, $param);
  60. }
  61. return $page;
  62. }
  63. }