A
A
Andrey Elsukov2020-07-15 11:36:29
Yii
Andrey Elsukov, 2020-07-15 11:36:29

Link in GridView column?

There is this code:

echo GridView::widget([
                'dataProvider' => $dataProvider,
                'showHeader' => false,
                'summary' => false,
                'tableOptions' => [
                    'class' => "table table-striped"
                ],
                'columns' => [
                    [
                      'attribute' => 'title',
                    ],
                    
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{view}'
                    ],
                ],
                
            ]);


How to make it so that instead of "Eyes" (
[
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{view}'
                    ],
), thanks to which we go to the transition to the desired record, this transition was 'title' and the column in which it is located?
Thanks in advance for your reply)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-15
@Dropsen

Good afternoon.

[
'template' => '{view}',
'buttons' => [
    'view' => function($url, $model, $key){
       return Html::a($model->title, $url)
    }
  ]
]

Check out the documentation.
https://www.yiiframework.com/doc/api/2.0/yii-grid-... .
You can also follow the link directly from the title column.
[
   'attribute' => 'title',
   'value' => function($model){
       return Html::a($model->title, ['controller/action', 'id' => $model->id])
    }
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question