Yii permission control method (three methods), yii permission control. Yii permission control method (three methods). yii permission control this article describes the yii permission control method. For your reference, see the following three methods: yii permission control (three methods) and yii permission control.
This article describes the yii permission control method. We will share this with you for your reference. The details are as follows:
The following three types are extracted:
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. use plug-ins (such as: right)
public function filters(){ return array( 'rights', );}
3. mixed mode:
/** * @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();}
If you have the permission to open some actions, you can use allowedActions:
public function allowedActions(){ return 'autocomplate,autocomplate2';}
I hope this article will help you design PHP programs based on the Yii Framework.
Articles you may be interested in:
- Directory structure, entry file, and route settings in Yii Getting Started Tutorial
- Yii installation and hello world
- Yii PHP Framework practical Getting Started Tutorial (details)
- Yii Query Builder usage example tutorial
- How to beautify YII by using url components
- Yii removes the star number in the required field
- Batch delete of CGridView in Yii
- Yii database query method
- YiiFramework knowledge point summary (graphic tutorial)
Permission (three methods), yii permission control this article describes the yii permission control method. For your reference, see the following three types :...