Can somebody give me an example how to change the standard-button for let’s say the ‘view Glyph button’ . I have to post one of the datafields in the searchModel as parameter in the url.
Can somebody give me an example how to change the standard-button for let’s say the ‘view Glyph button’ . I have to post one of the datafields in the searchModel as parameter in the url.
Hope this helps
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {login}',
'buttons' => [
'login' => function($key, $client) {
$url = 'some code here'
return Html::a('LOGIN', $url, ['target' => '_blank']);
}
]
Big thanks Flarpy, works like a charm, not completely what I intend to do but I got it and now it’s clear to me. There is much BS on the internet how to do this. This one works.
This is what I used to handover parameters in the ActionColumn button.
$model[‘id’] and $model[‘role_id’] are of-course values coming from the ‘result-record’.
The code does not work for the delete-button because the controller only accepts POST variables in the deleteAction, that is why we set data-method to POST for the delete-button.
[
'class' => '\kartik\grid\ActionColumn',
'template' => '{view} {update} {delete}',
'buttons' => [
'view' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),]);
}
],
'buttons' => [
'update' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Update'),]);
}
],
'buttons' => [
'delete' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model['id']], [
'title' => Yii::t('app', 'Delete'), 'data-confirm' => Yii::t('app', 'Are you sure you want to delete this Record?'),'data-method' => 'post']);
}
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
$url = 'index.php?r=role-defenition/view&id='.$model['id'].'&role_id='.$model['role_id'];
return $url;
}
if($action === 'update') {
$url = 'index.php?r=role-defenition/update&id='.$model['id'].'&role_id='.$model['role_id'];
return $url;
}
}
]