Base.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // 栏目菜单(nav)
  66. $categories = Category::getList(['is_nav'=>1]);
  67. View::assign('categories', $categories);
  68. // 一般栏目
  69. $cate_lists = Category::getList(['type'=>1]);
  70. View::assign('cate_lists', $cate_lists);
  71. }
  72. }