V
V
Vlad Osadchyi2018-11-13 01:24:06
Yii
Vlad Osadchyi, 2018-11-13 01:24:06

How to pass a third-party variable to urlCreator()?

When generating links for ActionColumn GridView::widget, you need to pass a get parameter that is stored in a separate variable, how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-13
@VladOsadchyi

Good evening.
Override buttons in ActionColumn .
Approximately like this:

[
   'class' => 'yii\grid\ActionColumn',
   'buttons' => [
        'view' => function($url, $model, $key){
            return Html::a('view',$url . '/car/' . $model->username ); // в общем подставьте свои параметры.
        },
        'update' => function($url, $model, $key){
            // your code
        },
        'delete' => function($url, $model, $key){
            // your code
        }        
    ]
]

You can even add your own button))) Only then you need to redefine the template for the buttons
Something like this:
[
   'class' => 'yii\grid\ActionColumn',
   'template' => '{view} {update} {delete} {customButton}',
   'buttons' => [
        'view' => function($url, $model, $key){
            return Html::a('view',$url . '/car/' . $model->username ); // в общем подставьте свои параметры.
        },
        'update' => function($url, $model, $key){
            // your code
        },
        'delete' => function($url, $model, $key){
            // your code
        },
        'customButton' => function($url, $model, $key){
              return Html::a('CustomButton', ['/site/index']); // параметры, конечно же, подставьте свои.
       }      
    ]
]

And the parameter can be passed like this:
'view' => function($url, $model, $key) use ($your_param){
            return Html::a('view',$url . '/car/' . $your_param ); // в общем подставьте свои параметры.
        },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question