Commit 5c79ab20 by disem Committed by Carsten Brandt

Added key param to ActionColumn button Closure

fixes #4602, close #4624
parent 689fc137
...@@ -171,6 +171,7 @@ Yii Framework 2 Change Log ...@@ -171,6 +171,7 @@ Yii Framework 2 Change Log
- Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code) - Enh #4559: Added `beforeValidateAll` and `afterValidateAll` callbacks to `ActiveForm` (Alex-Code)
- Enh #4566: Added client validation support for image validator (Skysplit, qiangxue) - Enh #4566: Added client validation support for image validator (Skysplit, qiangxue)
- Enh #4581: Added ability to disable url encoding in `UrlRule` (tadaszelvys) - 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: 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: 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) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......
...@@ -54,20 +54,20 @@ class ActionColumn extends Column ...@@ -54,20 +54,20 @@ class ActionColumn extends Column
* signature: * signature:
* *
* ```php * ```php
* function ($url, $model) { * function ($url, $model, $key) {
* // return the button HTML code * // return the button HTML code
* } * }
* ``` * ```
* *
* where `$url` is the URL that the column creates for the button, and `$model` is the model object * where `$url` is the URL that the column creates for the button, `$model` is the model object
* being rendered for the current row. * 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 * 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): * editable (here assuming you have a status field that indicates that):
* *
* ```php * ```php
* [ * [
* 'update' => function ($url, $model) { * 'update' => function ($url, $model, $key) {
* return $model->status == 'editable' ? Html::a('Update', $url) : ''; * return $model->status == 'editable' ? Html::a('Update', $url) : '';
* }; * };
* ], * ],
...@@ -155,7 +155,7 @@ class ActionColumn extends Column ...@@ -155,7 +155,7 @@ class ActionColumn extends Column
if (isset($this->buttons[$name])) { if (isset($this->buttons[$name])) {
$url = $this->createUrl($name, $model, $key, $index); $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 { } else {
return ''; return '';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment