This article illustrates the method of Yii permission control. Share to everyone for your reference, specific as follows:
Here are excerpts of the following 3:
1. Through AccessControl:
Public function Filters ()
{return
array (
' AccessControl ',//Perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This are used by the ' AccessControl ' filter.
* @return Array access control rules/public
function accessrules ()
{return
array (
' Allow ',//Allow authenticated users to access all actions
' users ' =>array (' @ '),
Array (' Deny ',// Deny all users '
users ' =>array (' * '),)
;
}
2. Through the plugin (such as: right)
Public function Filters ()
{return
array (
' rights ',
);
}
3. Blending mode:
/**
* @return Array Action Filters
*
/Public Function filters ()
{return
array (
' Updateown + Update ',//Apply This filter to the update action.
' Rights ',
);
}
/**
* Filter to 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 a own post/and has the permission to does so
.
if (Yii::app ()->user->checkaccess (' Postupdateown ', Array (' userid ' => $post->author_id))
$ Filterchain->removeat (1);
$filterChain->run ();
}
If you have permission to open certain actions on the basis of permission, you can pass allowedactions:
Public Function allowedactions ()
{return
' Autocomplate,autocomplate2 ';
}
I hope this article will help you with the PHP program design based on the YII framework.