You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When GridView is based on ActiveDataProvider the Model::generateAttributeLabel() will be called even when the label is explicitly specified in GridView::columns. The correct label value (from GridView::columns) is rendered but the incorrect label value is still being generated and never used. In such situation automatic label generation should not happen because it is pointless and also interferes with user intention of raising an error instead of generating values for labels that are not explicitly defined (by throwing exception in overridden generateAttributeLabel() method).
What steps will reproduce the problem?
// Database table for this class has 2 attributes: "attr1" and "attr2".classMyModelextends \yii\db\ActiveRecord
{
publicfunctionattributeLabels() {
return [
'attr1' => 'Label for attr1',
// Label for 'attr2' is NOT defined here
];
}
publicfunctiongenerateAttributeLabel($name) {
thrownew \yii\base\InvalidArgumentException('Label not defined!');
}
}
$grid = new \yii\grid\GridView([
'dataProvider' => new \yii\data\ActiveDataProvider([
'query' => MyModel::find(),
]),
'columns' => [
'attr1',
'attr2:text:Label for attr2', // Defines label for 'attr2'.
],
]);
$grid->renderTableHeader();
What is the expected result?
MyModel::generateAttributeLabel('attr2') IS NEVER CALLED and exception is not thrown.
What do you get instead?
MyModel::generateAttributeLabel('attr2') IS CALLED and throws exception.
Additional info
Q
A
Yii version
2.0.48.1
The text was updated successfully, but these errors were encountered:
When
GridView
is based onActiveDataProvider
theModel::generateAttributeLabel()
will be called even when the label is explicitly specified inGridView::columns
. The correct label value (fromGridView::columns
) is rendered but the incorrect label value is still being generated and never used. In such situation automatic label generation should not happen because it is pointless and also interferes with user intention of raising an error instead of generating values for labels that are not explicitly defined (by throwing exception in overriddengenerateAttributeLabel()
method).What steps will reproduce the problem?
What is the expected result?
MyModel::generateAttributeLabel('attr2')
IS NEVER CALLED and exception is not thrown.What do you get instead?
MyModel::generateAttributeLabel('attr2')
IS CALLED and throws exception.Additional info
The text was updated successfully, but these errors were encountered: