yii權(quán)限控制的方法(三種方法)
本文實(shí)例講述了yii權(quán)限控制的方法。分享給大家供大家參考,具體如下:
這里摘錄以下3種:
1. 通過(guò)accessControl:
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow authenticated users to access all actions
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
2. 通過(guò)插件(如:right)
public function filters()
{
return array(
'rights',
);
}
3. 混合模式:
/**
* @return array action filters
*/
public function filters()
{
return array(
'updateOwn + update', // Apply this filter only for the update action.
'rights',
);
}
/**
* Filter method for checking whether the currently logged in user
* is the author of the post being accessed.
*/
public function filterUpdateOwn($filterChain)
{
$post=$this->loadModel();
// Remove the 'rights' filter if the user is updating an own post
// and has the permission to do so.
if(Yii::app()->user->checkAccess('PostUpdateOwn', array('userid'=>$post->author_id)))
$filterChain->removeAt(1);
$filterChain->run();
}
如果有權(quán)限的基礎(chǔ)上,開(kāi)放某些動(dòng)作的權(quán)限,可以通過(guò)allowedActions:
public function allowedActions()
{
return 'autocomplate,autocomplate2';
}
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
- Yii2搭建后臺(tái)并實(shí)現(xiàn)rbac權(quán)限控制完整實(shí)例教程
- Yii2 rbac權(quán)限控制之菜單menu實(shí)例教程
- 淺析Yii中使用RBAC的完全指南(用戶角色權(quán)限控制)
- 深入解析yii權(quán)限分級(jí)式訪問(wèn)控制的實(shí)現(xiàn)(非RBAC法)
- yii2 RBAC使用DbManager實(shí)現(xiàn)后臺(tái)權(quán)限判斷的方法
- Yii2 rbac權(quán)限控制之rule教程詳解
- 深入淺析Yii admin的權(quán)限控制
- Yii2 rbac權(quán)限控制操作步驟實(shí)例教程
- Yii中srbac權(quán)限擴(kuò)展模塊工作原理與用法分析
- Yii框架ACF(accessController)簡(jiǎn)單權(quán)限控制操作示例
相關(guān)文章
laravel7學(xué)習(xí)之無(wú)限級(jí)分類的最新實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于laravel7學(xué)習(xí)之無(wú)限級(jí)分類的最新實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
CodeIgniter配置之routes.php用法實(shí)例分析
這篇文章主要介紹了CodeIgniter配置之routes.php用法,結(jié)合實(shí)例形式分析了routes.php中常用配置參數(shù)的含義及具體使用技巧,需要的朋友可以參考下2016-01-01
Thinkphp將二維數(shù)組變?yōu)闃?biāo)簽適用的一維數(shù)組方法總結(jié)
這篇文章主要介紹了Thinkphp將二維數(shù)組變?yōu)闃?biāo)簽適用的一維數(shù)組方法,總結(jié)了常見(jiàn)的轉(zhuǎn)化數(shù)組方法,非常實(shí)用,需要的朋友可以參考下2014-10-10
Thinkphp5分頁(yè)后攜帶參數(shù)跳轉(zhuǎn)傳遞功能實(shí)現(xiàn)
這篇文章主要介紹了Thinkphp5分頁(yè)后攜帶參數(shù)進(jìn)行跳轉(zhuǎn)傳遞,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06
PHP調(diào)用FFmpeg實(shí)現(xiàn)視頻切片
這篇文章主要為大家詳細(xì)介紹了PHP如何調(diào)用FFmpeg實(shí)現(xiàn)視頻切片功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-02-02
PHP 閉包獲取外部變量和global關(guān)鍵字聲明變量的區(qū)別講解
閉包是一個(gè)常見(jiàn)的概念,我們通??梢詫⑵渑c回調(diào)函數(shù)配合使用,可以使代碼更加簡(jiǎn)潔易讀。這篇文章主要介紹了PHP 閉包獲取外部變量和global關(guān)鍵字聲明變量的區(qū)別,需要的朋友可以參考下2017-12-12

