I need to add a new, custom button in the Yii2 ActionColumn . Using the examples available on the Internet, I managed to create a closure for rendering a custom button, and now it displays the default URL.
But I need this with a custom URL.
I managed to do this by overriding the value of $url so that my custom button close function is served with the URL generated using other function parameters, for example:
'buttons' => [ 'see' => function ($url, $model, $key) { $options = [ 'title' => Yii::t('yii', 'See in frontend'), 'aria-label' => Yii::t('yii', 'See'), 'data-pjax' => '0', ]; $url = \yii\helpers\Url::toRoute(['lab/index', 'lab' => $key]); return Html::a('<span class="glyphicon glyphicon-asterisk"></span>', $url, $options); } ],
It works, but it is not too professional. I wanted to use the urlCreator property, as shown in the Kartik Example from the Yii Forum :
'urlCreator' => function ($action, $model, $key, $index) { if ($action === 'see') { return \yii\helpers\Url::toRoute(['lab/index', 'lab' => $key]); } }
But this example does not work. It generates the correct URL for my custom button and leaves the default buttons that do not work, without any URL. This is understandable if you assume how urlCreator works. But how to solve this problem? How can I access the ActionColumn to use the controller property to create the URLs for the default buttons, or how to get it to generate these URLs for me?