Base.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * 构造方法
  29. * @access public
  30. * @param App $app 应用对象
  31. */
  32. public function __construct(App $app)
  33. {
  34. $this->app = $app;
  35. $this->request = $this->app->request;
  36. // 控制器初始化
  37. $this->initialize();
  38. }
  39. // 初始化
  40. protected function initialize()
  41. {
  42. // 菜单
  43. $categories = Category::where('is_nav', 1)->order(['sort desc'])->select();
  44. View::assign('categories', $categories);
  45. if ($this->request->has('_aside')==false) {
  46. $this->aside();
  47. }
  48. }
  49. /**
  50. * 侧边栏
  51. */
  52. protected function aside()
  53. {
  54. $cate_lists = Category::where('template', 'article')->select();
  55. $hits_lists = Article::getListByCid(0, 9, ['hits' => 'desc']);
  56. $top_lists = Article::getTop(7);
  57. $time_lists = Article::createTimeArchive();
  58. View::assign([
  59. 'cate_lists' => $cate_lists,
  60. 'hits_lists' => $hits_lists,
  61. 'top_lists' => $top_lists,
  62. 'time_lists' => $time_lists
  63. ]);
  64. }
  65. }