yii权限控制的方法(三种方法)
框架(架构)  /  管理员 发布于 7年前   148
本文实例讲述了yii权限控制的方法。分享给大家供大家参考,具体如下: 这里摘录以下3种: 1. 通过accessControl: 2. 通过插件(如:right) 3. 混合模式: 如果有权限的基础上,开放某些动作的权限,可以通过allowedActions: 希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。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('*'), ), );}
public function filters(){ return array( 'rights', );}
/** * @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();}
public function allowedActions(){ return 'autocomplate,autocomplate2';}
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号