M
M
My joy2018-02-12 16:13:21
Yii
My joy, 2018-02-12 16:13:21

User->can with "OR" mode?

Hello others.
How to make user->can(role) check only in OR mode?
those. it is necessary to give access to the functionality to several roles, and in order not to write 5-10 times
user->can('role1') || user->can('role2') || ...
, is it possible to somehow do a check on the list (array) ala right away
user->can(['role1', 'role2', ...])
?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
davidnum95, 2018-02-12
@t-alexashka

Two options:
1. Move the check into a static function.
2. Write your User class, redefine the can function and slip it as a component.

A
Artem, 2018-02-12
@proudmore

An option with the correct structure of roles, permissions and rules that will not require multiple checks is not considered?

M
Maxim Timofeev, 2018-02-12
@webinar

Isn't that what permission is for?
Create, give it to different roles. Or even a list of users.
If there is some logic by which roles and / or users are selected, then there is not permission for this, but rules:
www.yiiframework.com/doc-2.0/guide-security-author...
If it is not suitable, for religious reasons, proposed (although, as for me, the rbac yii2 scheme covers any whim), then - pick up a pencil and write your bike

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question