I
I
idaho2018-05-31 11:51:19
Yii
idaho, 2018-05-31 11:51:19

YII2 How to show delete and change buttons only for post author?

The standard view generated by GII has delete and change buttons.
How can I make them visible only to the author of the post?
the controller has a check for the role of the author when switching to editing or deleting:

if (!Yii::$app->user->can('updateOwnPost', ['post'=>$model])){
            throw new ForbiddenHttpException("You must be Owner of this Pedigree");
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mysterion, 2018-05-31
@Mysterion

'visibleButtons' = [
    'update' => Yii::$app->user->can('updateOwnPost')
    'delete' => Yii::$app->user->can('updateOwnPost')
]

M
Maxim Timofeev, 2018-05-31
@webinar

wrap the buttons exactly the same way, what stopped you from trying it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question