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
62b4a645
Commit
62b4a645
authored
Aug 27, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crud generator WIP
parent
f48508e3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
1 deletion
+108
-1
Generator.php
framework/yii/gii/generators/crud/Generator.php
+82
-1
form.php
framework/yii/gii/generators/crud/form.php
+10
-0
controller.php
framework/yii/gii/generators/crud/templates/controller.php
+8
-0
model.php
framework/yii/gii/generators/crud/templates/model.php
+8
-0
No files found.
framework/yii/gii/generators/crud/Generator.php
View file @
62b4a645
...
@@ -7,6 +7,10 @@
...
@@ -7,6 +7,10 @@
namespace
yii\gii\generators\crud
;
namespace
yii\gii\generators\crud
;
use
yii\db\ActiveRecord
;
use
yii\gii\CodeFile
;
use
yii\web\Controller
;
/**
/**
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
...
@@ -14,6 +18,10 @@ namespace yii\gii\generators\crud;
...
@@ -14,6 +18,10 @@ namespace yii\gii\generators\crud;
*/
*/
class
Generator
extends
\yii\gii\Generator
class
Generator
extends
\yii\gii\Generator
{
{
public
$modelClass
;
public
$controllerID
;
public
$baseControllerClass
=
'yii\web\Controller'
;
public
function
getName
()
public
function
getName
()
{
{
return
'CRUD Generator'
;
return
'CRUD Generator'
;
...
@@ -25,11 +33,84 @@ class Generator extends \yii\gii\Generator
...
@@ -25,11 +33,84 @@ class Generator extends \yii\gii\Generator
operations for the specified data model.'
;
operations for the specified data model.'
;
}
}
public
function
rules
()
{
return
array_merge
(
parent
::
rules
(),
array
(
array
(
'modelClass, controllerID, baseControllerClass'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'modelClass, controllerID, baseControllerClass'
,
'required'
),
array
(
'modelClass'
,
'match'
,
'pattern'
=>
'/^[\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'modelClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
ActiveRecord
::
className
())),
array
(
'controllerID'
,
'match'
,
'pattern'
=>
'/^[a-z\\-\\/]*$/'
,
'message'
=>
'Only a-z, dashes (-) and slashes (/) are allowed.'
),
array
(
'baseControllerClass'
,
'match'
,
'pattern'
=>
'/^[\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'baseControllerClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
Controller
::
className
())),
));
}
public
function
attributeLabels
()
{
return
array_merge
(
parent
::
attributeLabels
(),
array
(
'modelClass'
=>
'Model Class'
,
'controllerID'
=>
'Controller ID'
,
'baseControllerClass'
=>
'Base Controller Class'
,
));
}
/**
* @inheritdoc
*/
public
function
hints
()
{
return
array
(
'modelClass'
=>
'This is the ActiveRecord class associated with the table that CRUD will be built upon.
You should provide a fully qualified class name, e.g., <code>app\models\Post</code>.'
,
'controllerID'
=>
'CRUD controllers are often named after the model class name that they are dealing with.
Controller ID should be in lower case and may contain module ID(s) separated by slashes. For example:
<ul>
<li><code>order</code> generates <code>OrderController.php</code></li>
<li><code>order-item</code> generates <code>OrderItemController.php</code></li>
<li><code>admin/user</code> generates <code>UserController.php</code> within the <code>admin</code> module.</li>
</ul>'
,
'baseControllerClass'
=>
'This is the class that the new CRUD controller class will extend from.
You should provide a fully qualified class name, e.g., <code>yii\web\Controller</code>.'
,
);
}
public
function
requiredTemplates
()
{
return
array
(
'controller.php'
,
);
}
/**
* @inheritdoc
*/
public
function
stickyAttributes
()
{
return
array
(
'baseControllerClass'
);
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
generate
()
public
function
generate
()
{
{
return
array
();
$files
=
array
();
$files
[]
=
new
CodeFile
(
$this
->
controllerFile
,
$this
->
render
(
'controller.php'
)
);
$files
=
scandir
(
$this
->
getTemplatePath
());
foreach
(
$files
as
$file
)
{
if
(
is_file
(
$templatePath
.
'/'
.
$file
)
&&
CFileHelper
::
getExtension
(
$file
)
===
'php'
&&
$file
!==
'controller.php'
)
{
$files
[]
=
new
CodeFile
(
$this
->
viewPath
.
DIRECTORY_SEPARATOR
.
$file
,
$this
->
render
(
$templatePath
.
'/'
.
$file
)
);
}
}
return
$files
;
}
}
}
}
framework/yii/gii/generators/crud/form.php
0 → 100644
View file @
62b4a645
<?php
/**
* @var yii\base\View $this
* @var yii\widgets\ActiveForm $form
* @var yii\gii\generators\crud\Generator $generator
*/
echo
$form
->
field
(
$generator
,
'modelClass'
);
echo
$form
->
field
(
$generator
,
'controllerID'
);
echo
$form
->
field
(
$generator
,
'baseControllerClass'
);
framework/yii/gii/generators/crud/templates/controller.php
0 → 100644
View file @
62b4a645
<?php
/**
* Created by JetBrains PhpStorm.
* User: qiang
* Date: 8/26/13
* Time: 5:22 PM
* To change this template use File | Settings | File Templates.
*/
framework/yii/gii/generators/crud/templates/model.php
0 → 100644
View file @
62b4a645
<?php
/**
* Created by JetBrains PhpStorm.
* User: qiang
* Date: 8/26/13
* Time: 5:22 PM
* To change this template use File | Settings | File Templates.
*/
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