BaseController.class.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Base\Controller;
  3. use Think\Controller;
  4. use Admin\Model\ColumnModel;
  5. /**
  6. * 基础控制器
  7. * @author Superbee
  8. *
  9. */
  10. class BaseController extends Controller {
  11. /**
  12. * 初始化模板
  13. */
  14. public function _initialize() {
  15. $this->checkLogin();
  16. }
  17. /**
  18. * 检查用户是否登录
  19. */
  20. private function checkLogin() {
  21. $admin = $this->getCurrentAdmin();
  22. if (empty($admin)) {
  23. $actionName = strtolower(CONTROLLER_NAME);
  24. if (!in_array($actionName, array("login"))) {
  25. header("location: " . __APP__ . "/Home/Login/login");
  26. exit;
  27. }
  28. }
  29. // $this->initMenu();
  30. }
  31. /**
  32. * 从session里面获得当前登录的管理员信息
  33. */
  34. public function getCurrentAdmin() {
  35. return isset($_SESSION['admin']) ? session('admin') : null;
  36. }
  37. private function initMenu() {
  38. $column = new ColumnModel();
  39. $temp = $column->menu();
  40. $this->assign('menu', $temp);
  41. }
  42. }