diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 66a6bc5946..60de81d72d 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -72,6 +72,7 @@ Yii Framework 2 Change Log - Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark) - Chg #3383: Added `$type` parameter to `IdentityInterface::findIdentityByAccessToken()` (qiangxue) - Chg #3531: \yii\grid\GridView now allows any character (except ":") in the attribute part of the shorthand syntax for columns (rawtaz) +- Chg #3544: Added `$key` as a parameter to the callable specified via `yii\grid\DataColumn::value` (mdmunir) - Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue) - Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue) - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe) diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index 21d8939252..110dff5ede 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -37,3 +37,8 @@ Upgrade from Yii 2.0 Beta * If you are using `dropDownList()`, `listBox()`, `activeDropDownList()`, or `activeListBox()` of `yii\helpers\Html`, and your list options use multiple blank spaces to format and align option label texts, you need to specify the option `encodeSpaces` to be true. + +* If you are using `yii\grid\GridView` and have configured a data column to use a PHP callable + to return cell values (via `yii\grid\DataColumn::value`), you may need to adjust the signature + of the callable to be `function ($model, $key, $index, $widget)`. The `$key` parameter was newly added + in this release. diff --git a/framework/grid/DataColumn.php b/framework/grid/DataColumn.php index b1a79b0041..5263189b74 100644 --- a/framework/grid/DataColumn.php +++ b/framework/grid/DataColumn.php @@ -51,7 +51,7 @@ class DataColumn extends Column public $label; /** * @var string|\Closure an anonymous function that returns the value to be displayed for every data model. - * The signature of this function is `function ($model, $index, $widget)`. + * The signature of this function is `function ($model, $key, $index, $widget)`. * If this is not set, `$model[$attribute]` will be used to obtain the value. * * You may also set this property to a string representing the attribute name to be displayed in this column. @@ -176,7 +176,7 @@ class DataColumn extends Column if (is_string($this->value)) { return ArrayHelper::getValue($model, $this->value); } else { - return call_user_func($this->value, $model, $index, $this); + return call_user_func($this->value, $model, $key, $index, $this); } } elseif ($this->attribute !== null) { return ArrayHelper::getValue($model, $this->attribute);