diff --git a/extensions/gii/assets/gii.js b/extensions/gii/assets/gii.js index 0790770324..cafe845969 100644 --- a/extensions/gii/assets/gii.js +++ b/extensions/gii/assets/gii.js @@ -151,6 +151,21 @@ yii.gii = (function ($) { $('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1); }).change(); + //model generator: translate table name to model class + $('#generator-tablename').on('blur', function () { + var tableName = $(this).val(); + if (tableName && tableName !== '*'){ + $.ajax({ + type: "GET", + url: "default/classify", + data: {tableName: tableName}, + success: function (modelName) { + $('#generator-modelclass').val(modelName); + } + }); + } + }); + // hide message category when I18N is disabled $('form #generator-enablei18n').change(function () { $('form .field-generator-messagecategory').toggle($(this).is(':checked')); diff --git a/extensions/gii/controllers/DefaultController.php b/extensions/gii/controllers/DefaultController.php index 438fc3b222..af1cdbf6bb 100644 --- a/extensions/gii/controllers/DefaultController.php +++ b/extensions/gii/controllers/DefaultController.php @@ -8,6 +8,7 @@ namespace yii\gii\controllers; use Yii; +use yii\helpers\Inflector; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -126,4 +127,12 @@ class DefaultController extends Controller throw new NotFoundHttpException("Code generator not found: $id"); } } + + /** + * @param string $tableName + * @return string + */ + public function actionClassify($tableName){ + return Inflector::classify($tableName); + } }