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
1d9e6b6f
Commit
1d9e6b6f
authored
Apr 23, 2014
by
horizons2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use tableprefix on gii model generator
use tableprefix on gii model generator
parent
cbcc7b6a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Generator.php
extensions/gii/generators/model/Generator.php
+23
-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 @
1d9e6b6f
...
...
@@ -30,6 +30,7 @@ class Generator extends \yii\gii\Generator
public
$baseClass
=
'yii\db\ActiveRecord'
;
public
$generateRelations
=
true
;
public
$generateLabelsFromComments
=
false
;
public
$useTablePefix
=
false
;
/**
* @inheritdoc
...
...
@@ -65,6 +66,7 @@ class Generator extends \yii\gii\Generator
[[
'baseClass'
],
'validateClass'
,
'params'
=>
[
'extends'
=>
ActiveRecord
::
className
()]],
[[
'generateRelations'
,
'generateLabelsFromComments'
],
'boolean'
],
[[
'enableI18N'
],
'boolean'
],
[[
'useTablePefix'
],
'boolean'
],
[[
'messageCategory'
],
'validateMessageCategory'
,
'skipOnEmpty'
=>
false
],
]);
}
...
...
@@ -534,6 +536,27 @@ 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 useTablePefix == true return with {{%}} depending of the position of the prefix
*/
public
function
generateTablename
(
$tableName
)
{
if
(
!
$this
->
useTablePefix
)
{
return
$tableName
;
}
else
{
$db
=
$this
->
getDbConnection
();
$patterns
=
[];
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 @
1d9e6b6f
...
...
@@ -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 @
1d9e6b6f
...
...
@@ -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
,
'useTablePefix'
)
->
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