本文整理汇总了PHP中Authority::action_alias方法的典型用法代码示例。如果您正苦于以下问题:PHP Authority::action_alias方法的具体用法?PHP Authority::action_alias怎么用?PHP Authority::action_alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Authority
的用法示例。
在下文中一共展示了Authority::action_alias方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
return array('initialize' => function ($user) {
// The initialize method (this Closure function) will be ran on every page load when the bundle get's started.
// A User Object will be passed into this method and is available via $user
// The $user variable is a instantiated User Object (application/models/user.php)
// First, let's group together some "Actions" so we can later give a user access to multiple actions at once
Authority::action_alias('manage', array('create', 'read', 'update', 'delete'));
Authority::action_alias('moderate', array('update', 'delete'));
// If a user doesn't have any roles, we don't have to give him permissions so we can stop right here.
if (count($user->roles) === 0) {
return false;
}
if ($user->has_role('admin')) {
// The logged in user is an admin, we allow him to perform manage actions (create, read, update, delete) on "all" "Resources".
Authority::allow('manage', 'all');
// Let's say we want to "Deny" the admin from adding accounts if his age is below 21 (i don't mean to discriminate ;)
// Since we have the User object, and it has an "age" property, we can make a simple if statement.
if ($user->age < 21) {
// Too young! we "deny" the user to create users, i'm sorry...
Authority::deny('create', 'User');
}
// Let's make it a little harder, we don't want the admin to be able to delete his own User account, but has to be allowed to delete other Users.
// We only know that the "Resource" is a User, But we don't know the User id, we can send that information to the Rule Closure, in the Closure below, the argument is called $that_user.
// We also pass in the logged in user, since the Closure is outside of the scope where this comment is in.
Authority::deny('delete', 'User', function ($that_user) use($user) {
// If the id of the User that we are trying to delete is equal to our logged in user, we return true, meaning the Deny Rule will be set.
return (int) $that_user->id === (int) $user->id;
});
}
if ($user->has_role('store_owner')) {