ChannelController.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Home\Controller;
  3. /**
  4. * 频道
  5. * @author Devil
  6. * @blog http://gong.gg/
  7. * @version 0.0.1
  8. * @datetime 2016-12-01T21:51:08+0800
  9. */
  10. class ChannelController extends CommonController
  11. {
  12. /**
  13. * [_initialize 前置操作-继承公共前置方法]
  14. * @author Devil
  15. * @blog http://gong.gg/
  16. * @version 0.0.1
  17. * @datetime 2016-12-03T12:39:08+0800
  18. */
  19. public function _initialize()
  20. {
  21. // 调用父类前置方法
  22. parent::_initialize();
  23. }
  24. /**
  25. * [Index 频道]
  26. * @author Devil
  27. * @blog http://gong.gg/
  28. * @version 0.0.1
  29. * @datetime 2016-12-06T21:31:53+0800
  30. */
  31. public function Index()
  32. {
  33. // 模型对象
  34. $m = M('Article');
  35. // 条件
  36. $where = $this->GetIndexWhere();
  37. // 分页
  38. $number = 10;
  39. $page_param = array(
  40. 'number' => $number,
  41. 'total' => $m->where($where)->count(),
  42. 'where' => $_GET,
  43. 'url' => U('Home/Channel/Index'),
  44. );
  45. $page = new \My\Page($page_param);
  46. // 获取列表
  47. $list = LayoutArticleDataHandle($m->where($where)->limit($page->GetPageStarNumber(), $number)->order('id desc')->select());
  48. // 分页
  49. $this->assign('page_html', $page->GetPageHtml());
  50. // 数据列表
  51. $this->assign('list', $list);
  52. // 布局+模块列表
  53. $this->assign('data', $this->GetLayoutList('channel'));
  54. // 友情链接
  55. $this->assign('link', LayoutLink('channel', 1));
  56. // 频道数据
  57. $channel = $this->GetChannelData();
  58. // 浏览器标题
  59. $title = isset($channel[I('id')]) ? $channel[I('id')] : '';
  60. $this->assign('home_seo_site_title', $this->GetBrowserSeoTitle($title, MyC('home_seo_channel_browser')));
  61. $this->display('Index');
  62. }
  63. /**
  64. * [GetChannelData 获取频道数据]
  65. * @author Devil
  66. * @blog http://gong.gg/
  67. * @version 0.0.1
  68. * @datetime 2017-02-25T14:38:33+0800
  69. */
  70. private function GetChannelData()
  71. {
  72. $data = S(C('cache_home_channel_key'));
  73. if(empty($data))
  74. {
  75. $data = M('ArticleClass')->getField('id,name');
  76. }
  77. return $data;
  78. }
  79. /**
  80. * [GetIndexWhere 文章列表条件]
  81. * @author Devil
  82. * @blog http://gong.gg/
  83. * @version 0.0.1
  84. * @datetime 2016-12-10T22:16:29+0800
  85. */
  86. private function GetIndexWhere()
  87. {
  88. $where = array();
  89. // 文章分类id
  90. if(!empty($_REQUEST['id']))
  91. {
  92. $where['article_class_id'] = intval(I('id'));
  93. }
  94. return $where;
  95. }
  96. }
  97. ?>