Answer the question
In order to leave comments, you need to log in
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
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'))
{
// делаем выборку с помощью КурсыПользователи для каждого по своим данным
}
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 questionAsk a Question
731 491 924 answers to any question