HomeBaseController.class.php 1.9 KB

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