diff --git a/framework/yii/gii/generators/model/Generator.php b/framework/yii/gii/generators/model/Generator.php
index 6253dc3..4f6646e 100644
--- a/framework/yii/gii/generators/model/Generator.php
+++ b/framework/yii/gii/generators/model/Generator.php
@@ -8,7 +8,6 @@
namespace yii\gii\generators\model;
use Yii;
-use yii\base\InvalidConfigException;
use yii\db\Connection;
use yii\gii\CodeFile;
use yii\helpers\Inflector;
@@ -26,7 +25,7 @@ class Generator extends \yii\gii\Generator
public $modelClass;
public $baseClass = '\yii\db\ActiveRecord';
public $generateRelations = true;
- public $commentsAsLabels = false;
+ public $generateLabelsFromComments = false;
public function getName()
@@ -46,13 +45,13 @@ class Generator extends \yii\gii\Generator
array('db, ns, tableName, baseClass', 'required'),
array('db, modelClass', 'match', 'pattern' => '/^\w+$/', 'message' => 'Only word characters are allowed.'),
array('ns, baseClass', 'match', 'pattern' => '/^[\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'),
- array('tableName', 'match', 'pattern' => '/^(\w+\.)?[\w\.\*]+$/', 'message' => 'Only word characters, asterisks and dot are allowed.'),
+ array('tableName', 'match', 'pattern' => '/^(\w+\.)?\w+\*?$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'),
array('db', 'validateDb'),
array('ns', 'validateNamespace'),
array('tableName', 'validateTableName'),
array('modelClass', 'validateModelClass'),
array('baseClass', 'validateBaseClass'),
- array('generateRelations, commentsAsLabels', 'boolean'),
+ array('generateRelations, generateLabelsFromComments', 'boolean'),
));
}
@@ -65,7 +64,28 @@ class Generator extends \yii\gii\Generator
'modelClass' => 'Model Class',
'baseClass' => 'Base Class',
'generateRelations' => 'Generate Relations',
- 'commentsAsLabels' => 'Use Column Comments as Attribute Labels',
+ 'generateLabelsFromComments' => 'Generate Labels from DB Comments',
+ );
+ }
+
+ public function hints()
+ {
+ return array(
+ 'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., app\models
',
+ 'db' => 'This is the ID of the DB application component.',
+ 'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. tbl_post
.
+ The table name may consist of the DB schema part if needed, e.g. public.tbl_post
.
+ The table name may contain an asterisk at the end to match multiple table names, e.g. tbl_*
.
+ In this case, multiple ActiveRecord classes will be generated, one for each matching table name.',
+ 'modelClass' => 'This is the name of the ActiveRecord class to be generated. The class name should not contain
+ the namespace part as it is specified in "Namespace". You do not need to specify the class name
+ if "Table Name" contains an asterisk at the end, in which case multiple ActiveRecord classes will be generated.',
+ 'baseClass' => 'This is the base class of the new ActiveRecord class. It should be a fully qualified namespaced class name.',
+ 'generateRelations' => 'This indicates whether the generator should generate relations based on
+ foreign key constraints it detects in the database. Note that if your database contains too many tables,
+ you may want to uncheck this option to accelerate the code generation process.',
+ 'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels
+ by using the comments of the corresponding DB columns.',
);
}
@@ -78,7 +98,7 @@ class Generator extends \yii\gii\Generator
public function stickyAttributes()
{
- return array('ns', 'db', 'baseClass', 'generateRelations', 'commentsAsLabels');
+ return array('ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments');
}
public function getDbConnection()
@@ -147,7 +167,7 @@ class Generator extends \yii\gii\Generator
{
$labels = array();
foreach ($table->columns as $column) {
- if ($this->commentsAsLabels && !empty($column->comment)) {
+ if ($this->generateLabelsFromComments && !empty($column->comment)) {
$labels[$column->name] = $column->comment;
} else {
$label = Inflector::camel2words($column->name);
diff --git a/framework/yii/gii/generators/model/form.php b/framework/yii/gii/generators/model/form.php
index 3aa9ffe..9eca27c 100644
--- a/framework/yii/gii/generators/model/form.php
+++ b/framework/yii/gii/generators/model/form.php
@@ -11,4 +11,4 @@ echo $form->field($generator, 'ns');
echo $form->field($generator, 'baseClass');
echo $form->field($generator, 'db');
echo $form->field($generator, 'generateRelations')->checkbox();
-echo $form->field($generator, 'commentsAsLabels')->checkbox();
+echo $form->field($generator, 'generateLabelsFromComments')->checkbox();