Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
48e3739b
Commit
48e3739b
authored
Aug 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
model generator WIP
parent
a6248b4a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
Generator.php
framework/yii/gii/generators/model/Generator.php
+27
-7
form.php
framework/yii/gii/generators/model/form.php
+1
-1
No files found.
framework/yii/gii/generators/model/Generator.php
View file @
48e3739b
...
...
@@ -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
$
commentsAsLabel
s
=
false
;
public
$
generateLabelsFromComment
s
=
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,
commentsAsLabel
s'
,
'boolean'
),
array
(
'generateRelations,
generateLabelsFromComment
s'
,
'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., <code>app\models</code>'
,
'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. <code>tbl_post</code>.
The table name may consist of the DB schema part if needed, e.g. <code>public.tbl_post</code>.
The table name may contain an asterisk at the end to match multiple table names, e.g. <code>tbl_*</code>.
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'
,
'
commentsAsLabel
s'
);
return
array
(
'ns'
,
'db'
,
'baseClass'
,
'generateRelations'
,
'
generateLabelsFromComment
s'
);
}
public
function
getDbConnection
()
...
...
@@ -147,7 +167,7 @@ class Generator extends \yii\gii\Generator
{
$labels
=
array
();
foreach
(
$table
->
columns
as
$column
)
{
if
(
$this
->
commentsAsLabel
s
&&
!
empty
(
$column
->
comment
))
{
if
(
$this
->
generateLabelsFromComment
s
&&
!
empty
(
$column
->
comment
))
{
$labels
[
$column
->
name
]
=
$column
->
comment
;
}
else
{
$label
=
Inflector
::
camel2words
(
$column
->
name
);
...
...
framework/yii/gii/generators/model/form.php
View file @
48e3739b
...
...
@@ -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
,
'
commentsAsLabel
s'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'
generateLabelsFromComment
s'
)
->
checkbox
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment