码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp5_auth 权限认证

时间:2017-04-16 10:55:53      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:end   alt   oca   分享   this   extends   info   com   .com   

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 权限认证

标签:end   alt   oca   分享   this   extends   info   com   .com   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!