S
S
Sergey Semenko2015-02-11 14:18:28
Yii
Sergey Semenko, 2015-02-11 14:18:28

Yii2 - how to create a rule for editing?

How to correctly create a rule so that the post can be edited by a user with the admin role and the author of the post (post.user_id == user.id), if editing is allowed (allowEdit == true)? And how to use it then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Makarov, 2015-02-17
@abler98

There are two options.
1. In code:

if (Yii::$app->user->can('admin') || $post->user_id == Yii::$app->user->id) {
   // ...
}

2. Through the RBAC hierarchy: www.yiiframework.com/doc-2.0/guide-security-author...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question