博客列表 >tp5 auth 权限初始化

tp5 auth 权限初始化

夏日的烈风的博客
夏日的烈风的博客原创
2018年12月14日 11:40:061522浏览


public function _initialize()

{

parent::_initialize();

//判断是否已经登录

 

if( !Session::has('userinfo', 'admin') ) {

$this->error('Please login first', url('admin/Login/index'));

}

        $auth=new \think\Auth();

$userRow = Session::get('userinfo', 'admin');

//验证权限

$request = Request::instance();

$rule_name = $request->module().'/'.$request->controller().'/'.$request->action();

$this->uid = $userRow['id'];

$this->role_id = $userRow['role_id'];

 

//        var_dump($this->uid);

if($rule_name == 'admin/login/index' || $rule_name == 'admin/index/index') {

            $result = true;

        } else {

    $result = $auth->check($rule_name, $this->uid);

        }

        if(!$result){

            $this->error('您没有权限访问');

        }

/*if($userRow['administrator']!=1 && !$this->checkRule($this->uid, $rule_val)) {

$this->error(lang('Without the permissions page'));

}*/


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议