Base.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. abstract class Base
  15. {
  16. /**
  17. * Request实例
  18. * @var \think\Request
  19. */
  20. protected $request;
  21. /**
  22. * 应用实例
  23. * @var \think\App
  24. */
  25. protected $app;
  26. /**
  27. * 构造方法
  28. * @access public
  29. * @param App $app 应用对象
  30. */
  31. public function __construct(App $app)
  32. {
  33. $this->app = $app;
  34. $this->request = $this->app->request;
  35. // 控制器初始化
  36. $this->initialize();
  37. }
  38. // 初始化
  39. protected function initialize()
  40. {
  41. // 菜单
  42. $categories = Category::where('is_nav', 1)->order(['sort desc'])->select();
  43. View::assign('categories', $categories);
  44. if ($this->request->has('_aside')==false) {
  45. $this->aside();
  46. }
  47. }
  48. /**
  49. * 侧边栏
  50. */
  51. protected function aside()
  52. {
  53. $cate_lists = Category::where('template', 'article')->select();
  54. $hits_lists = Article::getListByCid(0, 9, ['hits' => 'desc']);
  55. $top_lists = Article::getTop(7);
  56. View::assign([
  57. 'cate_lists' => $cate_lists,
  58. 'hits_lists' => $hits_lists,
  59. 'top_lists' => $top_lists
  60. ]);
  61. }
  62. }