[英]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 .我有一个 GridView 有两列: country_name和一个带有名为Save按钮的actionColumn
。
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.我不知道如何将 Argentina 设置为 country_name,因为我的视图没有 model。 I only have data from the column country_name.我只有来自 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'
}
]
],
],
])
See ActionColumn:$buttons
documentation - model is passed as second argument to button callback:请参阅ActionColumn:$buttons
文档 - model 作为第二个参数传递给按钮回调:
'buttons' => [
'save' => function($url, $model) {
return Html::a('Save', ['/countries/view', 'country_name' => $model['country_name']]);
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.