-1

well I am using Kartik/Detail View and I only want to show the edit and delete button in the panel if the user is Admin. My code is :

<?= DetailView::widget([
        'model'=>$model,
        'condensed'=>true,
        'hover'=>true,
        'mode'=>DetailView::MODE_VIEW,
        'panel'=>[
            'heading'=>'Empleado ' . $model->RPE,
            'type'=>DetailView::TYPE_INFO,
        ],
        'buttons1' => '{view}',

Doing this im just only hidding the buttons but for everyone and just showing the view button but i don't want this.

In my GridView i am doing something like this but in the DeatailView didn't work, so i dont know how to implement this there.

['class' => 'kartik\grid\ActionColumn',
                'header' => 'Acciones',
                 'template'=> '{view} {update} {delete} ',

                'buttons'=> [
                    'update'=> function($url,$model) {
    if (Yii::$app->user->isGuest ? FALSE : (Yii::$app->user->identity->isAdmin)) {

                        return(Html::a( '<span class="glyphicon glyphicon-pencil"></span>', $url));

    } 

                    },

                    'delete'=>function($url,$model,$key) {


    if (Yii::$app->user->isGuest ? FALSE : (Yii::$app->user->identity->isAdmin)) {
                            return(Html::a('<span class="glyphicon glyphicon-trash"></span>', $url));

    } 

                    },

                ],
Adam Chubbuck
  • 1,612
  • 10
  • 27

1 Answers1

1

You can try this:

'buttons1' => Yii::$app->user->identity->isAdmin ? '{view} {delete}' : '{view}',
Vandro.nds
  • 442
  • 3
  • 8