Base.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @file Index.php
  5. * @date 2019-02-27 14:49:36
  6. * @author huwhis<huuwhois>
  7. * @version 0.0.6
  8. */
  9. namespace app\index\controller;
  10. use think\facade\View;
  11. use think\facade\Config;
  12. use think\App;
  13. use app\common\model\Article;
  14. use app\common\model\Category;
  15. use think\facade\Env;
  16. abstract class Base
  17. {
  18. /**
  19. * Request实例
  20. * @var \think\Request
  21. */
  22. protected $request;
  23. /**
  24. * 应用实例
  25. * @var \think\App
  26. */
  27. protected $app;
  28. /**
  29. * seo
  30. */
  31. protected $seo = [];
  32. /**
  33. * makeHtmlFile
  34. */
  35. protected $html = false;
  36. /**
  37. * 构造方法
  38. * @access public
  39. * @param App $app 应用对象
  40. */
  41. public function __construct(App $app)
  42. {
  43. $this->app = $app;
  44. $this->request = $this->app->request;
  45. $this->html = Config::get('app.html', false);
  46. // 控制器初始化
  47. $this->initialize();
  48. }
  49. // 初始化
  50. protected function initialize()
  51. {
  52. // SEO标题
  53. $system = \app\common\model\System::find(1);
  54. $this->seo = [
  55. 'title' => $system->title,
  56. 'key' => $system->key,
  57. 'des' => $system->des,
  58. ];
  59. View::assign('seo', $this->seo);
  60. if (Env::get('app.app_env', false)) {
  61. View::assign('bdtongji', $system->tongji);
  62. } else {
  63. View::assign('bdtongji', "");
  64. }
  65. // 菜单
  66. $categories = Category::where('is_nav', 1)->order(['sort desc'])->select();
  67. View::assign('categories', $categories);
  68. // 侧边栏
  69. if ($this->request->has('_aside')==false) {
  70. $this->aside();
  71. }
  72. }
  73. /**
  74. * 侧边栏
  75. */
  76. protected function aside()
  77. {
  78. $cate_lists = Category::where('template', 'article')->select();
  79. $hits_lists = Article::getListByCid(0, 9, ['hits' => 'desc']);
  80. $top_lists = Article::getTop(7);
  81. $time_lists = Article::createTimeArchive();
  82. $last_lists = Article::getListByCid(0, 9);
  83. View::assign([
  84. 'cate_lists' => $cate_lists,
  85. 'hits_lists' => $hits_lists,
  86. 'top_lists' => $top_lists,
  87. 'time_lists' => $time_lists,
  88. 'last_lists' => $last_lists,
  89. ]);
  90. }
  91. }