Base.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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->mailModel = new Mail();
  17. $this->assign('no_send', $this->mailModel->notSendMail());
  18. $this->check_login();
  19. $this->check_auth();
  20. }
  21. /**
  22. * 检测是否登录
  23. */
  24. private function check_login(){
  25. $admin = session('admin');
  26. if(empty($admin)){
  27. $this->redirect($this->request->root().'/base/login/login');
  28. }
  29. }
  30. /**
  31. * 检查权限
  32. */
  33. private function check_auth(){
  34. $m = $this->request->module ();
  35. $c = $this->request->controller ();
  36. $a = $this->request->action ();
  37. $rule_name = '/'.$m.'/'.$c.'/'.$a;
  38. $auth = new Auth();
  39. $admin = session('admin');
  40. $result = $auth->check($rule_name, $admin['id']);
  41. // if(!$result){
  42. // $this->error('您没有权限访问');
  43. // }
  44. }
  45. }