Commit 1b497ad7 by Alexander Makarov

Fixes #1107: if basename of Gii CRUD model and search model are equal than alias…

Fixes #1107: if basename of Gii CRUD model and search model are equal than alias is automatically used for search model
parent eeed9c3f
...@@ -12,6 +12,9 @@ use yii\helpers\StringHelper; ...@@ -12,6 +12,9 @@ use yii\helpers\StringHelper;
$controllerClass = StringHelper::basename($generator->controllerClass); $controllerClass = StringHelper::basename($generator->controllerClass);
$modelClass = StringHelper::basename($generator->modelClass); $modelClass = StringHelper::basename($generator->modelClass);
$searchModelClass = StringHelper::basename($generator->searchModelClass); $searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$searchModelAlias = $searchModelClass.'Search';
}
$pks = $generator->getTableSchema()->primaryKey; $pks = $generator->getTableSchema()->primaryKey;
$urlParams = $generator->generateUrlParams(); $urlParams = $generator->generateUrlParams();
...@@ -24,7 +27,7 @@ echo "<?php\n"; ...@@ -24,7 +27,7 @@ echo "<?php\n";
namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>; namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>;
use <?= ltrim($generator->modelClass, '\\') ?>; use <?= ltrim($generator->modelClass, '\\') ?>;
use <?= ltrim($generator->searchModelClass, '\\') ?>; use <?= ltrim($generator->searchModelClass, '\\') ?><?php if (isset($searchModelAlias)):?> as <?= $searchModelAlias ?><?php endif ?>;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use <?= ltrim($generator->baseControllerClass, '\\') ?>; use <?= ltrim($generator->baseControllerClass, '\\') ?>;
use yii\web\HttpException; use yii\web\HttpException;
...@@ -53,7 +56,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas ...@@ -53,7 +56,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
*/ */
public function actionIndex() public function actionIndex()
{ {
$searchModel = new <?= $searchModelClass ?>; $searchModel = new <?= isset($searchModelAlias) ? $searchModelAlias : $searchModelClass ?>;
$dataProvider = $searchModel->search($_GET); $dataProvider = $searchModel->search($_GET);
return $this->render('index', [ return $this->render('index', [
......
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