Hello,
Could someone in Yii2 team explain why there is a separation between buttons and urlCreator for action columns?
$actionCol = ['class' => 'yii\grid\ActionColumn',
'template' => '{view} {info}',
'buttons' => [
'info' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-info-sign"></span>', $url, [
'title' => Yii::t('app', 'Info'),
]);
}
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'info') {
$url = Yii::$app->controller->createUrl('xx'); // your own url generation logic
return $url;
}
}
];
I usually limit myself to this kind of mix:
'buttons' => [
'score' => function ($url, $model) {
$url = Url::to(['report/view', 'id' => $model->id, 'sort' => 'position']);
return Html::a(Icon::show('trophy', [], Icon::WHHG), $url, [
'title' => Yii::t('igolf', 'Enter scores'),
]);
},
]
which of course produces the same. What are the advantages and the reason to split url creation and button rendering?
Thank you.
P.