首页 > Web开发 > 详细

thinkphp5_auth 权限认证

时间:2017-04-16 10:56:21      阅读:457      评论:0      收藏:0      [点我收藏+]

1.Auth类文件引入

2.写一个公共类AuthInfo,所有要权限认证的类都继承此公共类AuthInfo

class AuthInfo extends Controller{
  protected function _initialize(){
    if(!session("?intel_uid")){
      echo "<script>alert(‘没有登陆!‘);window.location.href = ‘".url(‘index/index/index‘)."‘;</script>";
    }
    $uid = session(‘intel_uid‘);
    if($uid==1){
      return true;
    }
    $userArr=db(‘in_user‘)->where(‘id=‘.$uid)->find();
    $access_id = $userArr[‘role‘];
    $auth = new Auth();
    $name=request()->module().‘/‘.request()->controller().‘/‘.request()->action();
    if(!$auth->check($name,$access_id)){
      $this->error(‘没有权限!‘);
    }
  }
}

技术分享

thinkphp5_auth 权限认证

原文:http://www.cnblogs.com/walksnow/p/6718114.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!