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
ef01a8cb
Commit
ef01a8cb
authored
Aug 16, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gii WIP
parent
99281633
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
19 deletions
+61
-19
ActiveField.php
framework/yii/gii/ActiveField.php
+21
-0
Generator.php
framework/yii/gii/Generator.php
+3
-3
gii.js
framework/yii/gii/assets/gii.js
+9
-0
DefaultController.php
framework/yii/gii/controllers/DefaultController.php
+1
-0
Generator.php
framework/yii/gii/generators/controller/Generator.php
+11
-2
form.php
framework/yii/gii/generators/controller/views/form.php
+7
-8
_files.php
framework/yii/gii/views/default/_files.php
+5
-4
view.php
framework/yii/gii/views/default/view.php
+4
-2
No files found.
framework/yii/gii/ActiveField.php
0 → 100644
View file @
ef01a8cb
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\gii
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
ActiveField
extends
\yii\widgets\ActiveField
{
public
function
sticky
()
{
$this
->
options
[
'class'
]
.=
' sticky'
;
return
$this
;
}
}
framework/yii/gii/Generator.php
View file @
ef01a8cb
...
@@ -35,7 +35,7 @@ abstract class Generator extends Model
...
@@ -35,7 +35,7 @@ abstract class Generator extends Model
{
{
parent
::
init
();
parent
::
init
();
if
(
!
isset
(
$this
->
templates
[
'default'
]))
{
if
(
!
isset
(
$this
->
templates
[
'default'
]))
{
$this
->
templates
[
'default'
]
=
$this
->
getD
efaultTemplate
();
$this
->
templates
[
'default'
]
=
$this
->
d
efaultTemplate
();
}
}
}
}
...
@@ -60,13 +60,13 @@ abstract class Generator extends Model
...
@@ -60,13 +60,13 @@ abstract class Generator extends Model
return
array
();
return
array
();
}
}
public
function
getViewFile
()
public
function
formView
()
{
{
$class
=
new
ReflectionClass
(
$this
);
$class
=
new
ReflectionClass
(
$this
);
return
dirname
(
$class
->
getFileName
())
.
'/views/form.php'
;
return
dirname
(
$class
->
getFileName
())
.
'/views/form.php'
;
}
}
public
function
getD
efaultTemplate
()
public
function
d
efaultTemplate
()
{
{
$class
=
new
ReflectionClass
(
$this
);
$class
=
new
ReflectionClass
(
$this
);
return
dirname
(
$class
->
getFileName
())
.
'/templates'
;
return
dirname
(
$class
->
getFileName
())
.
'/templates'
;
...
...
framework/yii/gii/assets/gii.js
View file @
ef01a8cb
...
@@ -10,6 +10,15 @@ yii.gii = (function ($) {
...
@@ -10,6 +10,15 @@ yii.gii = (function ($) {
content
:
$hint
.
html
()
content
:
$hint
.
html
()
});
});
});
});
var
$checkAll
=
$
(
'#check-all'
);
$checkAll
.
click
(
function
()
{
$
(
'.code-files .check input'
).
prop
(
'checked'
,
this
.
checked
);
});
$
(
'.code-files .check input'
).
click
(
function
()
{
$checkAll
.
prop
(
'checked'
,
!
$
(
'.code-files .check input:not(:checked)'
).
length
);
});
$checkAll
.
prop
(
'checked'
,
!
$
(
'.code-files .check input:not(:checked)'
).
length
);
}
}
};
};
})(
jQuery
);
})(
jQuery
);
framework/yii/gii/controllers/DefaultController.php
View file @
ef01a8cb
...
@@ -43,6 +43,7 @@ class DefaultController extends Controller
...
@@ -43,6 +43,7 @@ class DefaultController extends Controller
$params
[
'result'
]
=
$generator
->
save
(
$files
,
$_POST
[
'answers'
]);
$params
[
'result'
]
=
$generator
->
save
(
$files
,
$_POST
[
'answers'
]);
}
else
{
}
else
{
$params
[
'files'
]
=
$files
;
$params
[
'files'
]
=
$files
;
$params
[
'answers'
]
=
isset
(
$_POST
[
'answers'
])
?
$_POST
[
'answers'
]
:
null
;
}
}
}
}
}
}
...
...
framework/yii/gii/generators/controller/Generator.php
View file @
ef01a8cb
...
@@ -20,6 +20,7 @@ class Generator extends \yii\gii\Generator
...
@@ -20,6 +20,7 @@ class Generator extends \yii\gii\Generator
{
{
public
$controller
;
public
$controller
;
public
$baseClass
=
'yii\web\Controller'
;
public
$baseClass
=
'yii\web\Controller'
;
public
$ns
=
'app\controllers'
;
public
$actions
=
'index'
;
public
$actions
=
'index'
;
public
function
getName
()
public
function
getName
()
...
@@ -36,12 +37,13 @@ class Generator extends \yii\gii\Generator
...
@@ -36,12 +37,13 @@ class Generator extends \yii\gii\Generator
public
function
rules
()
public
function
rules
()
{
{
return
array_merge
(
parent
::
rules
(),
array
(
return
array_merge
(
parent
::
rules
(),
array
(
array
(
'controller, actions, baseClass'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'controller, actions, baseClass
, ns
'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'controller, baseClass'
,
'required'
),
array
(
'controller, baseClass'
,
'required'
),
array
(
'controller'
,
'match'
,
'pattern'
=>
'/^[\w+\\/]*$/'
,
'message'
=>
'Only word characters and slashes are allowed.'
),
array
(
'controller'
,
'match'
,
'pattern'
=>
'/^[\w+\\/]*$/'
,
'message'
=>
'Only word characters and slashes are allowed.'
),
array
(
'actions'
,
'match'
,
'pattern'
=>
'/^\w+[\w\s,]*$/'
,
'message'
=>
'Only word characters, spaces and commas are allowed.'
),
array
(
'actions'
,
'match'
,
'pattern'
=>
'/^\w+[\w\s,]*$/'
,
'message'
=>
'Only word characters, spaces and commas are allowed.'
),
array
(
'baseClass'
,
'match'
,
'pattern'
=>
'/^[a-zA-Z_][\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'baseClass'
,
'match'
,
'pattern'
=>
'/^[a-zA-Z_][\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'baseClass'
,
'validateReservedWord'
,
'skipOnError'
=>
true
),
array
(
'baseClass'
,
'validateReservedWord'
),
array
(
'ns'
,
'match'
,
'pattern'
=>
'/^[a-zA-Z_][\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
));
));
}
}
...
@@ -51,6 +53,7 @@ class Generator extends \yii\gii\Generator
...
@@ -51,6 +53,7 @@ class Generator extends \yii\gii\Generator
'baseClass'
=>
'Base Class'
,
'baseClass'
=>
'Base Class'
,
'controller'
=>
'Controller ID'
,
'controller'
=>
'Controller ID'
,
'actions'
=>
'Action IDs'
,
'actions'
=>
'Action IDs'
,
'ns'
=>
'Namespace'
,
);
);
}
}
...
@@ -153,4 +156,10 @@ class Generator extends \yii\gii\Generator
...
@@ -153,4 +156,10 @@ class Generator extends \yii\gii\Generator
}
}
return
$module
->
getControllerPath
()
.
'/'
.
$id
.
'Controller.php'
;
return
$module
->
getControllerPath
()
.
'/'
.
$id
.
'Controller.php'
;
}
}
public
function
getViewFile
(
$action
)
{
$module
=
$this
->
getModule
();
return
$module
->
getViewPath
()
.
'/'
.
$this
->
getControllerID
()
.
'/'
.
$action
.
'.php'
;
}
}
}
framework/yii/gii/generators/controller/views/form.php
View file @
ef01a8cb
<?php
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
/**
/**
* @var yii\base\View $this
* @var yii\base\View $this
* @var yii\widgets\ActiveForm $form
* @var yii\widgets\ActiveForm $form
...
@@ -17,11 +13,14 @@ use yii\widgets\ActiveForm;
...
@@ -17,11 +13,14 @@ use yii\widgets\ActiveForm;
<li><code>admin/user</code> generates <code>UserController.php</code> within the <code>admin</code> module.</li>
<li><code>admin/user</code> generates <code>UserController.php</code> within the <code>admin</code> module.</li>
</ul>
</ul>
'
);
?>
'
);
?>
<?php
echo
$form
->
field
(
$generator
,
'baseClass'
)
->
hint
(
'
This is the class that the new controller class will extend from.
Please make sure the class exists and can be autoloaded.
'
);
?>
<?php
echo
$form
->
field
(
$generator
,
'actions'
)
->
hint
(
'
<?php
echo
$form
->
field
(
$generator
,
'actions'
)
->
hint
(
'
Provide one or multiple action IDs to generate empty action method(s) in the controller.
Provide one or multiple action IDs to generate empty action method(s) in the controller.
Separate multiple action IDs with commas or spaces.
Separate multiple action IDs with commas or spaces.
'
);
?>
'
);
?>
<?php
echo
$form
->
field
(
$generator
,
'ns'
)
->
sticky
()
->
hint
(
'
This is the namespace that the new controller class will should use.
'
);
?>
<?php
echo
$form
->
field
(
$generator
,
'baseClass'
)
->
sticky
()
->
hint
(
'
This is the class that the new controller class will extend from.
Please make sure the class exists and can be autoloaded.
'
);
?>
framework/yii/gii/views/default/_files.php
View file @
ef01a8cb
...
@@ -8,6 +8,7 @@ use yii\gii\CodeFile;
...
@@ -8,6 +8,7 @@ use yii\gii\CodeFile;
* @var $this \yii\base\View
* @var $this \yii\base\View
* @var $generator \yii\gii\Generator
* @var $generator \yii\gii\Generator
* @var CodeFile[] $files
* @var CodeFile[] $files
* @var array $answers
*/
*/
?>
?>
<table
class=
"table table-bordered table-striped table-condensed code-files"
>
<table
class=
"table table-bordered table-striped table-condensed code-files"
>
...
@@ -15,7 +16,7 @@ use yii\gii\CodeFile;
...
@@ -15,7 +16,7 @@ use yii\gii\CodeFile;
<tr>
<tr>
<th
class=
"file"
>
Code File
</th>
<th
class=
"file"
>
Code File
</th>
<th
class=
"action"
>
Action
</th>
<th
class=
"action"
>
Action
</th>
<th
class=
"check"
>
<th>
<?php
<?php
$count
=
0
;
$count
=
0
;
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
...
@@ -24,7 +25,7 @@ use yii\gii\CodeFile;
...
@@ -24,7 +25,7 @@ use yii\gii\CodeFile;
}
}
}
}
if
(
$count
>
1
)
{
if
(
$count
>
1
)
{
echo
'<input type="checkbox"
name="checkAll" id="check-all" /
>'
;
echo
'<input type="checkbox"
id="check-all"
>'
;
}
}
?>
?>
</th>
</th>
...
@@ -36,7 +37,7 @@ use yii\gii\CodeFile;
...
@@ -36,7 +37,7 @@ use yii\gii\CodeFile;
<td
class=
"file"
>
<td
class=
"file"
>
<?php
echo
Html
::
a
(
Html
::
encode
(
$file
->
getRelativePath
()),
array
(
'code'
,
'file'
=>
$i
),
array
(
'class'
=>
'view-code'
,
'rel'
=>
$file
->
path
));
?>
<?php
echo
Html
::
a
(
Html
::
encode
(
$file
->
getRelativePath
()),
array
(
'code'
,
'file'
=>
$i
),
array
(
'class'
=>
'view-code'
,
'rel'
=>
$file
->
path
));
?>
<?php
if
(
$file
->
operation
===
CodeFile
::
OP_OVERWRITE
)
:
?>
<?php
if
(
$file
->
operation
===
CodeFile
::
OP_OVERWRITE
)
:
?>
(
<?php
echo
Html
::
a
(
'diff'
,
array
(
'diff'
,
'file'
=>
$i
),
array
(
'class'
=>
'view-code'
,
'rel'
=>
$file
->
path
));
?>
)
<?php
echo
Html
::
a
(
'diff'
,
array
(
'diff'
,
'file'
=>
$i
),
array
(
'class'
=>
'view-code label label-warning'
,
'rel'
=>
$file
->
path
));
?>
<?php
endif
;
?>
<?php
endif
;
?>
</td>
</td>
<td
class=
"action"
>
<td
class=
"action"
>
...
@@ -54,7 +55,7 @@ use yii\gii\CodeFile;
...
@@ -54,7 +55,7 @@ use yii\gii\CodeFile;
echo
' '
;
echo
' '
;
}
else
{
}
else
{
$key
=
md5
(
$file
->
path
);
$key
=
md5
(
$file
->
path
);
echo
Html
::
checkBox
(
"answers[
$key
]"
);
echo
Html
::
checkBox
(
"answers[
$key
]"
,
isset
(
$answers
)
?
isset
(
$answers
[
$key
])
:
(
$file
->
operation
===
CodeFile
::
OP_NEW
)
);
}
}
?>
?>
</td>
</td>
...
...
framework/yii/gii/views/default/view.php
View file @
ef01a8cb
...
@@ -11,6 +11,7 @@ use yii\gii\CodeFile;
...
@@ -11,6 +11,7 @@ use yii\gii\CodeFile;
* @var yii\widgets\ActiveForm $form
* @var yii\widgets\ActiveForm $form
* @var string $result
* @var string $result
* @var CodeFile[] $files
* @var CodeFile[] $files
* @var array $answers
*/
*/
$this
->
title
=
$generator
->
getName
();
$this
->
title
=
$generator
->
getName
();
...
@@ -24,10 +25,10 @@ foreach ($generator->templates as $name => $path) {
...
@@ -24,10 +25,10 @@ foreach ($generator->templates as $name => $path) {
<p>
<?php
echo
$generator
->
getDescription
();
?>
</p>
<p>
<?php
echo
$generator
->
getDescription
();
?>
</p>
<?php
$form
=
ActiveForm
::
begin
();
?>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'fieldConfig'
=>
array
(
'class'
=>
'yii\gii\ActiveField'
))
);
?>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-lg-6"
>
<div
class=
"col-lg-6"
>
<?php
echo
$this
->
renderFile
(
$generator
->
getViewFile
(),
array
(
<?php
echo
$this
->
renderFile
(
$generator
->
formView
(),
array
(
'generator'
=>
$generator
,
'generator'
=>
$generator
,
'form'
=>
$form
,
'form'
=>
$form
,
));
?>
));
?>
...
@@ -51,6 +52,7 @@ foreach ($generator->templates as $name => $path) {
...
@@ -51,6 +52,7 @@ foreach ($generator->templates as $name => $path) {
echo
$this
->
render
(
'_files'
,
array
(
echo
$this
->
render
(
'_files'
,
array
(
'generator'
=>
$generator
,
'generator'
=>
$generator
,
'files'
=>
$files
,
'files'
=>
$files
,
'answers'
=>
$answers
,
));
));
}
}
?>
?>
...
...
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