thinkphp6使用权限验证插件验证权限

thinkphp6的插件扩展:http://sites.thinkphp.cn/1556332

我用的是https://github.com/wenhainan/thinkphp6-auth这个权限验证

1.按步骤创建数据表,

用户表:

权限表:

角色表:

用户所属角色表:

2.composer代码下来

composer代码下来后会在config文件多出一个auth.php, 在里面可以更改表的名字

3.composer下来后

 

3.使用

<?php
namespace app\admin\controller;

use app\BaseController;
use think\facade\View;
use think\wenhainan\Auth;

class AdminBase extends BaseController
{
    public function initialize()
    {
        $controller = strtolower(request()->controller());
        $action     = strtolower(request()->action());
        $auth       = Auth::instance();
        // dump($auth);exit;
        // 检测权限
        if(!$auth->check($controller.'-'.$action,1)){// 第一个参数是规则名称,第二个参数是用户UID
            //有显示操作按钮的权限
           dump('您没有权限访问');
        }        
    }
}

 


版权声明:本文为lmp5023原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。