T
T
tigra2016-03-08 01:27:53
Yii
tigra, 2016-03-08 01:27:53

How to properly use roles in YII?

there are 4 roles: active: 1, inactive: 0, banned: -1 and not registered guests
at all, respectively, each user has a status field.
I need to set those roles in the admin panel who will see a certain widget.
What is the best way to implement something like this? what is the course of action?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N++, 2016-03-08
@tigroid3

RBAC https://habrahabr.ru/post/235485/
create a role create a rule for the role if necessary
create a permision for the roles then
you need to set the user role or permisions.
if(Yii::$app->user->can('Permission or role name')){
// calling the widget
}
goo.gl/eNuJ5K
in the admin panel you will do something similar where editing users.
In simple terms, this is an additional field in the users table to show the widget or not.
ps Yii::$app->user->identity makes a request to the database every time
Yii::$app->user->getidentity(false)->show_widget takes the data previously received

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question