Yii permission control method (three methods), yii permission control _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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 :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.