Commit f747768f by Qiang Xue

improved search model generator.

parent 3ba9dcbe
......@@ -386,7 +386,9 @@ class Generator extends \yii\gii\Generator
$columns[$column->name] = $column->type;
}
}
$conditions = [];
$likeConditions = [];
$hashConditions = [];
foreach ($columns as $column => $type) {
switch ($type) {
case Schema::TYPE_SMALLINT:
......@@ -400,14 +402,24 @@ class Generator extends \yii\gii\Generator
case Schema::TYPE_TIME:
case Schema::TYPE_DATETIME:
case Schema::TYPE_TIMESTAMP:
$conditions[] = "\$query->andFilterWhere(['{$column}' => \$this->{$column}]);";
$hashConditions[] = "'{$column}' => \$this->{$column},";
break;
default:
$conditions[] = "\$query->andFilterWhere(['like', '{$column}', \$this->{$column}]);";
$likeConditions[] = "->andFilterWhere(['like', '{$column}', \$this->{$column}])";
break;
}
}
$conditions = [];
if (!empty($hashConditions)) {
$conditions[] = "\$query->andFilterWhere([\n"
. str_repeat(' ', 12) . implode("\n" . str_repeat(' ', 12), $hashConditions)
. "\n" . str_repeat(' ', 8) . "]);\n";
}
if (!empty($likeConditions)) {
$conditions[] = "\$query" . implode("\n" . str_repeat(' ', 12), $likeConditions) . ";\n";
}
return $conditions;
}
......
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