U
U
ukoHka2017-09-11 13:06:01
Yii
ukoHka, 2017-09-11 13:06:01

How to properly set up an AccessControl in Yii2?

The project assumes several groups of users. Groups do not mean Admin, Moderator, etc., but several users working on the same task. That is, in the entire project there are the same actions that users can perform only in relation to their group. For example, group A can add news that will be visible only to members of this group, and group B can add news only for their group. Of course, all the news are in one table in the database. Groups also have access levels, Admin, Moderator, etc.
The problem is that I do not fully understand the principle of operation AccessControland therefore cannot correctly prescribe the rules.
As far as I understood,createPermission('action')a rule is created for access to a specific action in the selected controller, and when creating a rule through Rule()in each action (except login, logout, profile, signUp) it is necessary to check through can(), sending to the current user. Are there any other easier ways? Prescribe in or directly in ? params['group_id']group_id
group_idbehaviorsCustomRule()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-09-11
@slo_nik

Good afternoon.
First, here is a link to the official documentation.
There is also a good blog where the author of the blog chews everything in detail and puts it in his mouth .
From myself I can add only one thing.
If you have a group id, there is also a news item that has the id of the group to which it belongs and there is a user who has the id of the same group to which he is subscribed, then what's the problem? Separate everything by group id. Check which group the user belongs to and send news by group id. If the user adds news, then check which group the user belongs to and then assign the id of this group to the news.
I would do so. Otherwise - RBAC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question