Frontend.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\controller;
  3. use app\common\library\Auth;
  4. use think\Controller;
  5. class Frontend extends Controller
  6. {
  7. /**
  8. *
  9. * @var \app\common\library\Auth
  10. */
  11. protected $user = null;
  12. /**
  13. * 布局模板
  14. * @var string
  15. */
  16. protected $layout = '';
  17. public function _initialize()
  18. {
  19. $modulename = $this->request->module();
  20. $controllername = strtolower($this->request->controller());
  21. $actionname = strtolower($this->request->action());
  22. $path = '/' . $modulename . '/' . str_replace('.', '/', $controllername) . '/' . $actionname;
  23. $this->user = Auth::instance();
  24. // 设置当前请求的URI
  25. $this->user->setRequestUri($path);
  26. // 检测当前是否登录并进行初始化
  27. $this->user->init();
  28. // 将auth对象渲染至视图
  29. $this->view->assign("user", $this->user);
  30. // 如果有使用模板布局
  31. if ($this->layout)
  32. {
  33. $this->view->engine->layout('layout/' . $this->layout);
  34. }
  35. }
  36. }