mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fix #19899: Fixed GridView
in some cases calling Model::generateAttributeLabel()
to generate label values that are never used
This commit is contained in:
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
||||
2.0.49 under development
|
||||
------------------------
|
||||
|
||||
- Bug #19899: Fixed `GridView` in some cases calling `Model::generateAttributeLabel()` to generate label values that are never used (PowerGamer1)
|
||||
- Bug #9899: Fix caching a MSSQL query with BLOB data type (terabytesoftw)
|
||||
- Bug #16208: Fix `yii\log\FileTarget` to not export empty messages (terabytesoftw)
|
||||
- Bug #19857: Fix AttributeTypecastBehavior::resetOldAttributes() causes "class has no attribute named" InvalidArgumentException (uaoleg)
|
||||
|
@ -183,15 +183,11 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
$sort->attributes[$attribute] = [
|
||||
'asc' => [$attribute => SORT_ASC],
|
||||
'desc' => [$attribute => SORT_DESC],
|
||||
'label' => $model->getAttributeLabel($attribute),
|
||||
];
|
||||
}
|
||||
} else {
|
||||
foreach ($sort->attributes as $attribute => $config) {
|
||||
if (!isset($config['label'])) {
|
||||
$sort->attributes[$attribute]['label'] = $model->getAttributeLabel($attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($sort->modelClass === null) {
|
||||
$sort->modelClass = $modelClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +191,12 @@ class Sort extends BaseObject
|
||||
* @since 2.0.33
|
||||
*/
|
||||
public $sortFlags = SORT_REGULAR;
|
||||
/**
|
||||
* @var string|null the name of the [[\yii\base\Model]]-based class used by the [[link()]] method to retrieve
|
||||
* attributes' labels. See [[link]] method for details.
|
||||
* @since 2.0.49
|
||||
*/
|
||||
public $modelClass;
|
||||
|
||||
|
||||
/**
|
||||
@ -363,7 +369,8 @@ class Sort extends BaseObject
|
||||
* @param array $options additional HTML attributes for the hyperlink tag.
|
||||
* There is one special attribute `label` which will be used as the label of the hyperlink.
|
||||
* If this is not set, the label defined in [[attributes]] will be used.
|
||||
* If no label is defined, [[\yii\helpers\Inflector::camel2words()]] will be called to get a label.
|
||||
* If no label is defined, it will be retrieved from the instance of [[modelClass]] (if [[modelClass]] is not null)
|
||||
* or generated from attribute name using [[\yii\helpers\Inflector::camel2words()]].
|
||||
* Note that it will not be HTML-encoded.
|
||||
* @return string the generated hyperlink
|
||||
* @throws InvalidConfigException if the attribute is unknown
|
||||
@ -388,6 +395,11 @@ class Sort extends BaseObject
|
||||
} else {
|
||||
if (isset($this->attributes[$attribute]['label'])) {
|
||||
$label = $this->attributes[$attribute]['label'];
|
||||
} elseif ($this->modelClass !== null) {
|
||||
$modelClass = $this->modelClass;
|
||||
/** @var \yii\base\Model $model */
|
||||
$model = $modelClass::instance();
|
||||
$label = $model->getAttributeLabel($attribute);
|
||||
} else {
|
||||
$label = Inflector::camel2words($attribute);
|
||||
}
|
||||
|
Reference in New Issue
Block a user