V
V
Vadim2018-08-14 14:18:58
Yii
Vadim, 2018-08-14 14:18:58

How to differentiate users in Yii2?

Tell me how to implement the following:
there is a table "Programs (id, id_course, title)" and "Courses (id, title)",
respectively, the relationship 1=n
"Courses" contains course1, course2, etc.
"Programs" contains program1, program2, and so on.
let's say user1 has access to course1 and all related programs, user2 = course2, etc. admin has access to all courses and programs
how to restrict access to CRUD, selection from tables and displaying information to certain users?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Bard, 2018-08-14
@serg_small_developer

I would do extra. a table in which he indicated the relationship between users and course tables, such as "CoursesUsers (id, id_course, id_user)", and then when selecting it, I checked it like this

if(!\Yii::$app->user->can('admin'))
{
//	делаем выборку с помощью КурсыПользователи для каждого по своим данным
}

those. if this is not an admin, then we select according to our data, and if not, then we omit it and select everything

M
Maxim Timofeev, 2018-08-14
@webinar

You make a queryModel there, you implement a method that inserts different conditions for different roles and then pass such a query to the dataProvider
'query' => SomeModel::find()->byRoles();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question