diff --git a/src/assets/js/gii.js b/src/assets/js/gii.js index c608b8371..c9aa70267 100644 --- a/src/assets/js/gii.js +++ b/src/assets/js/gii.js @@ -212,7 +212,26 @@ yii.gii = (function ($) { } $('.field-generator-caseinsensitive').toggle(!show); }).change(); - + $("#generator-singularize").click(function () { + var $this = $(this); + var $modelClass = $('#generator-modelclass'); + getModelClassName($this, $modelClass); + }) + + function getModelClassName($this, $modelClass) { + ajaxRequest = $.ajax({ + type: 'POST', + cache: false, + url: $this.data('action'), + data: $('#model-generator').serializeArray(), + success: function (response) { + $modelClass.val(response).blur(); + }, + error: function (XMLHttpRequest, textStatus, errorThrown) { + $modal.find('.modal-body').html('
' + XMLHttpRequest.responseText + '
'); + } + }); + } // model generator: translate table name to model class $('#model-generator #generator-tablename').on('blur', function () { var $this = $(this); diff --git a/src/generators/model/form.php b/src/generators/model/form.php index 18cc8ddc3..728e4d0ae 100644 --- a/src/generators/model/form.php +++ b/src/generators/model/form.php @@ -18,7 +18,12 @@ ] ]); echo $form->field($generator, 'standardizeCapitals')->checkbox(); -echo $form->field($generator, 'singularize')->checkbox(); +echo $form->field($generator, 'singularize')->checkbox([ + 'data' => [ + 'table-prefix' => $generator->getTablePrefix(), + 'action' => Url::to(['default/action', 'id' => 'model', 'name' => 'GenerateClassName']) + ] +]); echo $form->field($generator, 'modelClass'); echo $form->field($generator, 'ns'); echo $form->field($generator, 'baseClass');