Base.php 1014 B

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