Commit 9eb164f4 by Alexander Makarov

Merge pull request #2101 from thiagotalma/master

Best way to get the labels to search, the existing model.
parents d81f4811 e299b78a
...@@ -305,16 +305,22 @@ class Generator extends \yii\gii\Generator ...@@ -305,16 +305,22 @@ class Generator extends \yii\gii\Generator
*/ */
public function generateSearchLabels() public function generateSearchLabels()
{ {
$model = new $this->modelClass();
$attributeLabels = $model->attributeLabels();
$labels = []; $labels = [];
foreach ($this->getColumnNames() as $name) { foreach ($this->getColumnNames() as $name) {
if (!strcasecmp($name, 'id')) { if (isset($attributeLabels[$name])) {
$labels[$name] = 'ID'; $labels[$name] = $attributeLabels[$name];
} else { } else {
$label = Inflector::camel2words($name); if (!strcasecmp($name, 'id')) {
if (strcasecmp(substr($label, -3), ' id') === 0) { $labels[$name] = 'ID';
$label = substr($label, 0, -3) . ' ID'; } else {
$label = Inflector::camel2words($name);
if (strcasecmp(substr($label, -3), ' id') === 0) {
$label = substr($label, 0, -3) . ' ID';
}
$labels[$name] = $label;
} }
$labels[$name] = $label;
} }
} }
return $labels; return $labels;
......
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