Browse Source

Fixes #1107: if basename of Gii CRUD model and search model are equal than alias is automatically used for search model

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
1b497ad73b
  1. 7
      framework/yii/gii/generators/crud/templates/controller.php

7
framework/yii/gii/generators/crud/templates/controller.php

@ -12,6 +12,9 @@ use yii\helpers\StringHelper;
$controllerClass = StringHelper::basename($generator->controllerClass);
$modelClass = StringHelper::basename($generator->modelClass);
$searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$searchModelAlias = $searchModelClass.'Search';
}
$pks = $generator->getTableSchema()->primaryKey;
$urlParams = $generator->generateUrlParams();
@ -24,7 +27,7 @@ echo "<?php\n";
namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>;
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 <?= ltrim($generator->baseControllerClass, '\\') ?>;
use yii\web\HttpException;
@ -53,7 +56,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
*/
public function actionIndex()
{
$searchModel = new <?= $searchModelClass ?>;
$searchModel = new <?= isset($searchModelAlias) ? $searchModelAlias : $searchModelClass ?>;
$dataProvider = $searchModel->search($_GET);
return $this->render('index', [

Loading…
Cancel
Save