国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

yii權限控制的方法(三種方法)

2024-05-04 23:41:34
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了yii權限控制的方法,結合實例形式分析了通過accessControl,插件機混合模式三種方法實現權限控制的實現技巧,需要的朋友可以參考下
 

本文實例講述了yii權限控制的方法。分享給大家供大家參考,具體如下:

這里摘錄以下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();}

如果有權限的基礎上,開放某些動作的權限,可以通過allowedActions:

public function allowedActions(){  return 'autocomplate,autocomplate2';}

希望本文所述對大家基于Yii框架的PHP程序設計有所幫助。



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丽江市| 江门市| 沧源| 丹阳市| 乌海市| 温州市| 庄河市| 潮安县| 定远县| 龙江县| 凌云县| 三亚市| 历史| 辽宁省| 南阳市| 马山县| 嘉定区| 奉化市| 铁岭市| 霍州市| 会同县| 咸丰县| 望奎县| 剑川县| 石林| 汾阳市| 兰西县| 富裕县| 苏尼特右旗| 贵定县| 光山县| 安远县| 佳木斯市| 龙泉市| 奉贤区| 拉萨市| 花莲市| 彭泽县| 南澳县| 桐柏县| 葵青区|