Frontend.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\controller;
  3. use app\common\library\Auth;
  4. use app\common\model\Configvalue;
  5. use think\Config;
  6. use think\Controller;
  7. use think\Lang;
  8. class Frontend extends Controller
  9. {
  10. /**
  11. *
  12. * @var Auth
  13. */
  14. protected $user = null;
  15. /**
  16. * 布局模板
  17. * @var string
  18. */
  19. protected $layout = '';
  20. public function _initialize()
  21. {
  22. $modulename = $this->request->module();
  23. $controllername = strtolower($this->request->controller());
  24. $actionname = strtolower($this->request->action());
  25. $path = '/' . $modulename . '/' . str_replace('.', '/', $controllername) . '/' . $actionname;
  26. $this->user = Auth::instance();
  27. // 设置当前请求的URI
  28. $this->user->setRequestUri($path);
  29. // 检测当前是否登录并进行初始化
  30. $this->user->init();
  31. // 将auth对象渲染至视图
  32. $this->view->assign("user", $this->user);
  33. // 如果有使用模板布局
  34. if ($this->layout)
  35. {
  36. $this->view->engine->layout('layout/' . $this->layout);
  37. }
  38. // 语言检测
  39. $lang = Lang::detect();
  40. // 配置信息
  41. $config = [
  42. 'site' => Config::get("site"),
  43. 'upload' => Configvalue::upload(),
  44. 'modulename' => $modulename,
  45. 'controllername' => $controllername,
  46. 'actionname' => $actionname,
  47. 'jsname' => 'frontend/' . str_replace('.', '/', $controllername),
  48. 'moduleurl' => url("/{$modulename}", '', false),
  49. 'language' => $lang
  50. ];
  51. Lang::load(APP_PATH . $modulename . '/lang/' . $lang . '/' . str_replace('.', '/', $controllername) . '.php');
  52. $this->assign('site', Config::get("site"));
  53. $this->assign('config', $config);
  54. }
  55. }