# 源碼示例
~~~
<?php
//thikphp5.0
namespace app\***;
use think\Controller;
use think\Request;
use ***\Auth;//此處打星號是根據不同命名空間引用
class Common extends Controller
{
public function _initialize()
{
/*此處檢測用戶session()是否存在,判斷登陸*/
$auth = ***\Auth;
/*獲取獲取當前模塊名/控制器名/方法名*/
$request = Request::instance();
//echo $request->module().'/'.$request->controller().'/'.$request->action();
if(!$auth->check(
$request->module().'/'.$request->controller().'/'.$request->action(),<第二個參數放用戶主鍵id>)){
//check()方法中先介紹兩個參數,路徑和用戶id
return $this->error(‘抱歉,您沒有權限’);
}
}
}
~~~
```
/**
* 初始化方法
* 創建常量、公共方法
* 在所有的方法之前被調用
* thinkphp5.1
*/
protected function initialize()
{
// 權限檢測
$auth = Auth::instance();
$controller = request()->controller();
$action = request()->action();
if ( $action == '' ) {
$node = 'admin/' . $controller;
} else {
$node = 'admin/' . $controller . '/' . $action;
}
$uid = session('uid');
if ( !$auth -> check($node, $uid) ) {
$this -> error('您沒有權限訪問,請聯系管理員', 'admin/Index/console');
}
// 顯示側邊導航菜單
$this -> showNav();
}
```
- 空白目錄
- 數據表的創建
- auth _rule
- auth_group
- auth_group_access
- 權限示例
- Auth權限菜單
- Auth用戶組權限修改
- Auth用戶規則表
- Auth權限的使用
- 源碼示例
- thinkphp6auth
- 安裝與拓展
- auth
- thinkphp6.0權限擴展
- ThinkPHP3.2.3完整版中對Auth.class.php的使用
- ThinkPHP6.x中對Auth的使用[tp6-auth權限管理]
- Thinkphp6+Auth+LayuiAdmin+authtree權限管理
- 使用phpstudy安裝
- 使用寶塔安裝thinkphp
- thinkphp6 偽靜態配置(nginx和Apache)
- apiadmin安裝教程