Base.php 981 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\base\controller;
  3. use think\Controller;
  4. use think\Request;
  5. use think\Auth;
  6. /**
  7. * 创建控制器基类
  8. * @author Superbee
  9. *
  10. */
  11. class Base extends Controller{
  12. public function _initialize(){
  13. parent::_initialize();
  14. $this->assign("rootpath", $this->request->root());
  15. $this->check_login();
  16. $this->check_auth();
  17. }
  18. /**
  19. * 检测是否登录
  20. */
  21. private function check_login(){
  22. $admin = session('admin');
  23. if(empty($admin)){
  24. $this->redirect($this->request->root().'/base/login/login');
  25. }
  26. }
  27. /**
  28. * 检查权限
  29. */
  30. private function check_auth(){
  31. $m = $this->request->module ();
  32. $c = $this->request->controller ();
  33. $a = $this->request->action ();
  34. $rule_name = '/'.$m.'/'.$c.'/'.$a;
  35. $auth = new Auth();
  36. $id = session('admin')['id'];
  37. $result = $auth->check($rule_name, $id);
  38. // if(!$result){
  39. // $this->error('您没有权限访问');
  40. // }
  41. }
  42. }