I have this code:
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'bla',
'format' => 'url',
'value' => function ($data) {
return Html::url('site/index');
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
In grid view text is being generated with URL address.
/academia-new/advanced/admin/site/index
URL is working fine, but how can I set a text for link?
Use 'format' => 'raw'
instead of 'format' => 'url'
.
I got the solution from Samdark, contributor of yii. need to use format=>'raw':
...
'format' => 'raw',
'value'=>function ($data) {
return Html::a(Html::encode("View"),'site/index');
},
need to use Html::encode() to ecape XSS
solution:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label'=>'bla',
'format' => 'raw',
'value'=>function ($data) {
return Html::a(['site/index']);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With