国产探花免费观看_亚洲丰满少妇自慰呻吟_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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富民县| 宿迁市| 金华市| 正安县| 虞城县| 南汇区| 龙南县| 高陵县| 凤庆县| 临江市| 济南市| 肃北| 浦东新区| 南丹县| 石屏县| 楚雄市| 绵竹市| 潍坊市| 杂多县| 勐海县| 襄垣县| 陆川县| 乐陵市| 岱山县| 武威市| 津市市| 青州市| 五河县| 镇宁| 崇明县| 武夷山市| 行唐县| 清苑县| 保德县| 东城区| 高尔夫| 洛隆县| 太原市| 金川县| 子洲县| 桃江县|