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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
0480fcc2
Commit
0480fcc2
authored
Apr 23, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3222 from horizons2/patch-1
use tableprefix on gii model generator
parents
78e3eee2
b68f5b61
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
1 deletion
+24
-1
Generator.php
extensions/gii/generators/model/Generator.php
+22
-0
model.php
extensions/gii/generators/model/default/model.php
+1
-1
form.php
extensions/gii/generators/model/form.php
+1
-0
No files found.
extensions/gii/generators/model/Generator.php
View file @
0480fcc2
...
...
@@ -30,6 +30,7 @@ class Generator extends \yii\gii\Generator
public
$baseClass
=
'yii\db\ActiveRecord'
;
public
$generateRelations
=
true
;
public
$generateLabelsFromComments
=
false
;
public
$useTablePrefix
=
false
;
/**
* @inheritdoc
...
...
@@ -65,6 +66,7 @@ class Generator extends \yii\gii\Generator
[[
'baseClass'
],
'validateClass'
,
'params'
=>
[
'extends'
=>
ActiveRecord
::
className
()]],
[[
'generateRelations'
,
'generateLabelsFromComments'
],
'boolean'
],
[[
'enableI18N'
],
'boolean'
],
[[
'useTablePrefix'
],
'boolean'
],
[[
'messageCategory'
],
'validateMessageCategory'
,
'skipOnEmpty'
=>
false
],
]);
}
...
...
@@ -534,6 +536,26 @@ class Generator extends \yii\gii\Generator
}
/**
* Generates a the tablename with tableprefix usage .
* @param string $tableName the table name (which may contain schema prefix)
* @return string the generated table name if useTablePrefix == true return with {{%}} depending of the position of the prefix
*/
public
function
generateTablename
(
$tableName
)
{
if
(
!
$this
->
useTablePrefix
)
{
return
$tableName
;
}
else
{
$db
=
$this
->
getDbConnection
();
if
(
preg_match
(
"/^
{
$db
->
tablePrefix
}
(.*?)$/"
,
$tableName
,
$matches
))
{
$tableName
=
'{{%'
.
$matches
[
1
]
.
'}}'
;
}
elseif
(
preg_match
(
"/^(.*?)
{
$db
->
tablePrefix
}
$/"
,
$tableName
,
$matches
))
{
$tableName
=
'{{'
.
$matches
[
1
]
.
'%}}'
;
}
return
$tableName
;
}
}
/**
* Generates a class name from the specified table name.
* @param string $tableName the table name (which may contain schema prefix)
* @return string the generated class name
...
...
extensions/gii/generators/model/default/model.php
View file @
0480fcc2
...
...
@@ -39,7 +39,7 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
*/
public static function tableName()
{
return '
<?=
$
tableName
?>
';
return '
<?=
$
generator
->
generateTablename
(
$tableName
)
?>
';
}
<?php
if
(
$generator
->
db
!==
'db'
)
:
?>
...
...
extensions/gii/generators/model/form.php
View file @
0480fcc2
...
...
@@ -10,6 +10,7 @@ echo $form->field($generator, 'modelClass');
echo
$form
->
field
(
$generator
,
'ns'
);
echo
$form
->
field
(
$generator
,
'baseClass'
);
echo
$form
->
field
(
$generator
,
'db'
);
echo
$form
->
field
(
$generator
,
'useTablePrefix'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'generateRelations'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'generateLabelsFromComments'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'enableI18N'
)
->
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