yii權(quán)限控制的方法(三種方法)
本文實(shí)例講述了yii權(quán)限控制的方法。分享給大家供大家參考,具體如下:
這里摘錄以下3種:
1. 通過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. 通過插件(如: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ǔ)上,開放某些動作的權(quán)限,可以通過allowedActions:
public function allowedActions() { return 'autocomplate,autocomplate2'; }
希望本文所述對大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
- Yii2搭建后臺并實(shí)現(xiàn)rbac權(quán)限控制完整實(shí)例教程
- Yii2 rbac權(quán)限控制之菜單menu實(shí)例教程
- 淺析Yii中使用RBAC的完全指南(用戶角色權(quán)限控制)
- 深入解析yii權(quán)限分級式訪問控制的實(shí)現(xiàn)(非RBAC法)
- yii2 RBAC使用DbManager實(shí)現(xiàn)后臺權(quán)限判斷的方法
- Yii2 rbac權(quán)限控制之rule教程詳解
- 深入淺析Yii admin的權(quán)限控制
- Yii2 rbac權(quán)限控制操作步驟實(shí)例教程
- Yii中srbac權(quán)限擴(kuò)展模塊工作原理與用法分析
- Yii框架ACF(accessController)簡單權(quán)限控制操作示例
相關(guān)文章
Thinkphp5.0框架視圖view的循環(huán)標(biāo)簽用法示例
這篇文章主要介紹了Thinkphp5.0框架視圖view的循環(huán)標(biāo)簽用法,結(jié)合實(shí)例形式分析了thinkPHP5框架視圖view中的volist標(biāo)簽、foreach標(biāo)簽、for標(biāo)簽相關(guān)使用方法,需要的朋友可以參考下2019-10-10PHP生成json和xml類型接口數(shù)據(jù)格式
在做數(shù)據(jù)接口時(shí),我們通常要獲取第三方數(shù)據(jù)接口或者給第三方提供數(shù)據(jù)接口,而這些數(shù)據(jù)格式通常是以XML或者JSON格式傳輸,本文將介紹如何使用PHP生成XML格式數(shù)據(jù)供第三方調(diào)用以及如何獲取第三方提供的XML數(shù)據(jù)。2015-05-05laravel實(shí)現(xiàn)批量更新多條記錄的方法示例
最近在使用Laravel,想批量插入近千條數(shù)據(jù),通過網(wǎng)上找到了相關(guān)的解決方法,所以下面這篇文章主要給大家介紹了關(guān)于laravel實(shí)現(xiàn)批量更新多條記錄的相關(guān)資料,文中給出了詳細(xì)的示例代碼,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10PHP SPL標(biāo)準(zhǔn)庫之SplFixedArray使用實(shí)例
這篇文章主要介紹了PHP SPL標(biāo)準(zhǔn)庫之SplFixedArray使用實(shí)例,SplFixedArray主要是處理數(shù)組相關(guān)的主要功能,它是固定長度的,比普通的數(shù)組處理更快,需要的朋友可以參考下2015-05-05仿dedecms下拉分頁樣式修改的thinkphp分頁類實(shí)例
這篇文章主要介紹了仿dedecms下拉分頁樣式修改的thinkphp分頁類,可實(shí)現(xiàn)類似dedecms下拉分頁樣式的效果,需要的朋友可以參考下2014-10-10thinkPHP多域名情況下使用memcache方式共享session數(shù)據(jù)的實(shí)現(xiàn)方法
這篇文章主要介紹了thinkPHP多域名情況下使用memcache方式共享session數(shù)據(jù)的實(shí)現(xiàn)方法,較為詳細(xì)的分析了session的原理及多服務(wù)器共享session的相關(guān)技巧,需要的朋友可以參考下2016-07-07