yii权限控制的方法(三种方法),yii权限控制_PHP教程
yii
權限控制
yii权限控制的方法(三种方法),yii权限控制
本文实例讲述了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程序设计有所帮助。
您可能感兴趣的文章:
- Yii入门教程之目录结构、入口文件及路由设置
- Yii入门教程之Yii安装及hello world
- Yii PHP Framework实用入门教程(详细介绍)
- Yii查询生成器(Query Builder)用法实例教程
- YII使用url组件美化管理的方法
- yii去掉必填项中星号的方法
- Yii中CGridView实现批量删除的方法
- yii数据库的查询方法
- YiiFramework入门知识点总结(图文教程)
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

如何在Zend框架中使用ACL(Access Control List)進行權限控制
