Base.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\App;
  12. use app\common\model\Article;
  13. use app\common\model\Category;
  14. use think\facade\Env;
  15. abstract class Base
  16. {
  17. /**
  18. * Request实例
  19. * @var \think\Request
  20. */
  21. protected $request;
  22. /**
  23. * 应用实例
  24. * @var \think\App
  25. */
  26. protected $app;
  27. /**
  28. * seo
  29. */
  30. protected $seo = [];
  31. /**
  32. * 构造方法
  33. * @access public
  34. * @param App $app 应用对象
  35. */
  36. public function __construct(App $app)
  37. {
  38. $this->app = $app;
  39. $this->request = $this->app->request;
  40. // 控制器初始化
  41. $this->initialize();
  42. }
  43. // 初始化
  44. protected function initialize()
  45. {
  46. // SEO标题
  47. $system = \app\common\model\System::find(1);
  48. $this->seo = [
  49. 'title' => $system->title,
  50. 'key' => $system->key,
  51. 'des' => $system->des,
  52. ];
  53. View::assign('seo', $this->seo);
  54. // 菜单
  55. $categories = Category::where('is_nav', 1)->order(['sort desc'])->select();
  56. View::assign('categories', $categories);
  57. // 侧边栏
  58. if ($this->request->has('_aside')==false) {
  59. $this->aside();
  60. }
  61. }
  62. /**
  63. * 侧边栏
  64. */
  65. protected function aside()
  66. {
  67. $cate_lists = Category::where('template', 'article')->select();
  68. $hits_lists = Article::getListByCid(0, 9, ['hits' => 'desc']);
  69. $top_lists = Article::getTop(7);
  70. $time_lists = Article::createTimeArchive();
  71. $last_lists = Article::getListByCid(0, 9);
  72. View::assign([
  73. 'cate_lists' => $cate_lists,
  74. 'hits_lists' => $hits_lists,
  75. 'top_lists' => $top_lists,
  76. 'time_lists' => $time_lists,
  77. 'last_lists' => $last_lists,
  78. ]);
  79. }
  80. }