简体   繁体   中英

Yii2: how to pass data column in actionColumn?

I have a GridView with two columns: country_name and an actionColumn with a button called Save .

The Save button is a hiperlink to, for example:

http://localhost/countries/view?country_name=Argentina

I don't know how to set Argentina to country_name because my view doesn't have a model. I only have data from the column country_name.

GridView::widget([
  'dataProvider' => $dataProvider,
  'columns' => [
    'country_name',
    [
      'class' => 'yii\grid\ActionColumn',
      'template' => '{save}',
      'buttons' => [
        'save' => function($model) {
          return Html::a('Save', ['/countries/view', 'country_name' => $model['country_name']]); // Error: Illegal string offset 'country_name'
        }
      ]
    ],
  ],
])

I am using this Yii2 help .

See ActionColumn:$buttons documentation - model is passed as second argument to button callback:

'buttons' => [
    'save' => function($url, $model) {
        return Html::a('Save', ['/countries/view', 'country_name' => $model['country_name']]);
    }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM