《PHP編程:yii權(quán)限控制的方法(三種方法)》要點(diǎn):
本文介紹了PHP編程:yii權(quán)限控制的方法(三種方法),希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:YII框架
本文實(shí)例講述了yii權(quán)限控制的辦法.分享給大家供大家參考,具體如下:PHP學(xué)習(xí)
這里摘錄以下3種:PHP學(xué)習(xí)
1. 通過accessControl:PHP學(xué)習(xí)
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)PHP學(xué)習(xí)
public function filters() { return array( 'rights', ); }
3. 混合模式:PHP學(xué)習(xí)
/** * @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ǔ)上,開放某些動(dòng)作的權(quán)限,可以通過allowedActions:PHP學(xué)習(xí)
public function allowedActions() { return 'autocomplate,autocomplate2'; }
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所贊助.PHP學(xué)習(xí)
《PHP編程:yii權(quán)限控制的方法(三種方法)》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP編程:yii權(quán)限控制的方法(三種方法)》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/7979.html