thinkphp?? ?? ??? ???? ??
May 26, 2023 pm 02:36 PM???? ????? ???? ?? ???? ??? ?? ???? ????. ??? ???? ?? ? ???? ??? ???? ?? ?? ??? ?? ????? ?? ?? ? ??? ?????. PHP ????? ? ThinkPHP? ?? ?? ?? ??????? ??? ?? ?? ??? ?????. ??? ?? ???? ThinkPHP? ?? ??? ??? ????? ??? ???????.
1. ?? ??? ??
?? ??? ?? ???? ??? ??? ?? ????? ???? ? ?? ?? ???? ??? ? ??? ??? ??? ???? ?? ??? ???? ??? ?????. ?? ??, ????? ????? ???? ?? ????? ???? ??? ? ???, ?? ???? ????? ??? ? ? ?? ????? ??? ?? ????.
2. ?? ?? ?? ??
ThinkPHP ?????? ?? ??? ???? ? ?? ??? RBAC? ?? ?? ?? ??? ?????. RBAC(Role-Based Access Control), ? ?? ?? ??? ??? ??? ?? ??? ???? ?????. ?? ?? ?? ??? ??? ?? ??? ????, ????, ?? ?? ?? ? ? ????.
- RBAC
??????? RBAC? ?? ?? ??? ????? ThinkPHPLibraryThink? ?? Auth ???? ???? ???. ???? ??? ??? ????.
(1) ?? ???? ?? ???? ???? ?? ??? ??? ?????. ?? ??? ??? ???? ? ?? ??? ??? ? ????. ?? ????? ??? ?? ?? ??? ?? ?? ID? ?????.
????action1 | index | home | index | ||
---|---|---|---|---|---|
2 | add | home | index | add | |
3 | edit | home | index | edit | |
4 | delete | home | index | delete | |
?? ???(think_role) : | id | name |
admin | 1,2,3,4 | |
---|---|---|
1 | (2 ) ?? ??? ?? ????? Auth ???? ?????. ???? ??? ??? ????. | |
{ | } | ? ????? ?????? ?? ?? ???? ?? ID? ??? ????? ????. Auth ???? ???? ???? ?? ??? ?? $auth->check() ???? ?????. ??? ???? ?? ???? ?????. |
(1) ?? ??? ?? ????? Access ???? ?????. ???? ??? ??? ????.
class IndexController? Controller? ?????
{public function __construct() { parent::__construct(); //實例化Access類 $access = new ThinkAccess(); //獲取當(dāng)前用戶的角色ID $uid = session('user_id'); //獲取當(dāng)前請求的控制器和方法 $url = MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME; //定義權(quán)限節(jié)點列表 $nodes = array( 'Index/index',//首頁 'Index/add',//添加頁面 'Index/edit',//編輯頁面 'Index/delete',//刪除操作 ); //進行權(quán)限認證 if (!$access->check($nodes, $uid, $url)) { $this->error('您沒有訪問該頁面的權(quán)限!'); } }}
- ? ???? Access ???? ??????? ?? ???? ?? ID? ??? ???? ? ???? ???? $access->check() ???? ???? ?? ??? ?????. ?? ?? ??? ? ??? ??, ? ????? ???? ?????. ??? ???? ?? ???? ?????.
??? ???? ??
?????? Common ???? ??? ???? BaseController? ???? ????? ?? ?? ??? ??? ? ????. ?? ????? ? ????? ??? ??? ??? ? ??? ???? ? ????.
?? ?? ???? ?? ? ?? ???? ?? ???? ?? ???? ??? ??? ??? ??? ????. ??? ?? ??? ???? ??? ??? ???? ? ????. ??????? ???? ?? ???? ???? ?? ??? ??? ? ???, ??? ??? ? ??? ??? ?? ?? ? ????.
- ?? ?? ???
?? ??? ?? ?? ??? ?? ???? ??? ?? ??? ???? ? ????. ??????? ???? ??? ???? ???? ?? ID? ????? ???? ?? ??? ?? ???? ??? ? ????.
- 4. ??
- ?? ??? ???? ??? ???? ? ? ?????. ??? ???? ??? ???? ??? ??? ???? ? ????. ThinkPHP ???????? Auth ???? Access ???? ???? ?? ???? ?? ?? ??? ??? ? ????. ? ?? ??? ?? ThinkPHP?? ?? ??? ???? ??? ??? ??? ??? ? ???, ?? ?? ??? ??? ? ???? ????.
? ??? thinkphp?? ?? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)