diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7df2c8a..eb678bb 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -171,6 +171,7 @@ Yii Framework 2 Change Log - Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code) - Enh #4566: Added client validation support for image validator (Skysplit, qiangxue) - Enh #4581: Added ability to disable url encoding in `UrlRule` (tadaszelvys) +- Enh #4602: Added $key param in ActionColumn buttons Closure call (disem) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) diff --git a/framework/grid/ActionColumn.php b/framework/grid/ActionColumn.php index 513b60b..65ede7c 100644 --- a/framework/grid/ActionColumn.php +++ b/framework/grid/ActionColumn.php @@ -54,20 +54,20 @@ class ActionColumn extends Column * signature: * * ```php - * function ($url, $model) { + * function ($url, $model, $key) { * // return the button HTML code * } * ``` * - * where `$url` is the URL that the column creates for the button, and `$model` is the model object - * being rendered for the current row. + * where `$url` is the URL that the column creates for the button, `$model` is the model object + * being rendered for the current row, and `$key` is the key of the model in the data provider array. * * You can add further conditions to the button, for example only display it, when the model is * editable (here assuming you have a status field that indicates that): * * ```php * [ - * 'update' => function ($url, $model) { + * 'update' => function ($url, $model, $key) { * return $model->status == 'editable' ? Html::a('Update', $url) : ''; * }; * ], @@ -155,7 +155,7 @@ class ActionColumn extends Column if (isset($this->buttons[$name])) { $url = $this->createUrl($name, $model, $key, $index); - return call_user_func($this->buttons[$name], $url, $model); + return call_user_func($this->buttons[$name], $url, $model, $key); } else { return ''; }