Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
e04dca4d
Commit
e04dca4d
authored
Apr 18, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more rbac doc [skip ci]
parent
f7b8e7a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
authorization.md
docs/guide/authorization.md
+18
-6
No files found.
docs/guide/authorization.md
View file @
e04dca4d
...
...
@@ -408,24 +408,36 @@ class UserGroupRule extends Rule
public function execute($user, $item, $params)
{
$group = \Yii::$app->user->identity->group;
return $group == 1 && $item->name === 'admin' || $group == 2 && $item->name === 'author';
if ($item->name === 'admin') {
return $group == 1;
} elseif ($item->name === 'author') {
return $group == 1 || $group == 2;
} else {
return false;
}
}
}
$rule = new \app\rbac\UserGroupRule;
$auth->add($rule);
$admin = $auth->createRole('admin');
$admin->ruleName = $rule->name;
$auth->add($admin);
// ... add permissions as children of $admin ...
$author = $auth->createRole('author');
$author->ruleName = $rule->name;
$auth->add($author);
// ... add permissions as children of $author ...
$admin = $auth->createRole('admin');
$admin->ruleName = $rule->name;
$auth->add($admin);
$auth->addChild($admin, $author);
// ... add permissions as children of $admin ...
```
Note that in the above, because "author" is added as a child of "admin", when you implement the
`execute()`
method
of the rule class, you need to respect this hierarchy as well. That is why when the role name is "author",
the
`execute()`
method will return true if the user group is either 1 or 2 (meaning the user is in either "admin"
group or "author" group).
Next, configure
`authManager`
by listing the two roles in
[
[yii\rbac\ManagerInterface::defaultRoles
]
]:
```
php
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment