示例源碼如下,可根據不同應用場景進行更改
```
<?php
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(‘抱歉,您沒有權限’);
}
}
}
```