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
7f4e02cb
Commit
7f4e02cb
authored
Sep 03, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crud generator WIP
parent
3f2e7fa6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
83 deletions
+77
-83
Generator.php
framework/yii/gii/generators/controller/Generator.php
+1
-1
Generator.php
framework/yii/gii/generators/crud/Generator.php
+76
-9
index-grid.php
...rk/yii/gii/generators/crud/templates/views/index-grid.php
+0
-73
No files found.
framework/yii/gii/generators/controller/Generator.php
View file @
7f4e02cb
...
@@ -78,7 +78,7 @@ class Generator extends \yii\gii\Generator
...
@@ -78,7 +78,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'
,
'ns'
=>
'
Controller
Namespace'
,
);
);
}
}
...
...
framework/yii/gii/generators/crud/Generator.php
View file @
7f4e02cb
...
@@ -7,9 +7,11 @@
...
@@ -7,9 +7,11 @@
namespace
yii\gii\generators\crud
;
namespace
yii\gii\generators\crud
;
use
Yii
;
use
yii\base\Model
;
use
yii\base\Model
;
use
yii\db\ActiveRecord
;
use
yii\db\ActiveRecord
;
use
yii\gii\CodeFile
;
use
yii\gii\CodeFile
;
use
yii\helpers\Inflector
;
use
yii\web\Controller
;
use
yii\web\Controller
;
/**
/**
...
@@ -41,12 +43,15 @@ class Generator extends \yii\gii\Generator
...
@@ -41,12 +43,15 @@ class Generator extends \yii\gii\Generator
{
{
return
array_merge
(
parent
::
rules
(),
array
(
return
array_merge
(
parent
::
rules
(),
array
(
array
(
'modelClass, searchModelClass, controllerID, baseControllerClass'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'modelClass, searchModelClass, controllerID, baseControllerClass'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'modelClass,
searchModelClass,
controllerID, baseControllerClass'
,
'required'
),
array
(
'modelClass, controllerID, baseControllerClass'
,
'required'
),
array
(
'modelClass, searchModelClass'
,
'match'
,
'pattern'
=>
'/^[\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'modelClass, searchModelClass'
,
'match'
,
'pattern'
=>
'/^[\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'modelClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
ActiveRecord
::
className
())),
array
(
'modelClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
ActiveRecord
::
className
())),
array
(
'controllerID'
,
'match'
,
'pattern'
=>
'/^[a-z\\-\\/]*$/'
,
'message'
=>
'Only a-z, dashes (-) and slashes (/) are allowed.'
),
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'
,
'match'
,
'pattern'
=>
'/^[\w\\\\]*$/'
,
'message'
=>
'Only word characters and backslashes are allowed.'
),
array
(
'baseControllerClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
Controller
::
className
())),
array
(
'baseControllerClass'
,
'validateClass'
,
'params'
=>
array
(
'extends'
=>
Controller
::
className
())),
array
(
'enableSearch'
,
'boolean'
),
array
(
'indexWidgetType'
,
'in'
,
'range'
=>
array
(
'grid'
,
'list'
)),
array
(
'searchModelClass'
,
'validateSearchModelClass'
),
));
));
}
}
...
@@ -104,6 +109,13 @@ class Generator extends \yii\gii\Generator
...
@@ -104,6 +109,13 @@ class Generator extends \yii\gii\Generator
return
array
(
'baseControllerClass'
,
'indexWidgetType'
,
'enableSearch'
);
return
array
(
'baseControllerClass'
,
'indexWidgetType'
,
'enableSearch'
);
}
}
public
function
validateSearchModelClass
()
{
if
(
$this
->
enableSearch
&&
empty
(
$this
->
searchModelClass
))
{
$this
->
addError
(
'searchModelClass'
,
'Search Model Class cannot be empty.'
);
}
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -111,20 +123,75 @@ class Generator extends \yii\gii\Generator
...
@@ -111,20 +123,75 @@ class Generator extends \yii\gii\Generator
{
{
$files
=
array
();
$files
=
array
();
$files
[]
=
new
CodeFile
(
$files
[]
=
new
CodeFile
(
$this
->
controllerFile
,
$this
->
getControllerFile
()
,
$this
->
render
(
'controller.php'
)
$this
->
render
(
'controller.php'
)
);
);
$viewPath
=
$this
->
getViewPath
();
$files
=
scandir
(
$this
->
getTemplatePath
());
$templatePath
=
$this
->
getTemplatePath
()
.
'/views'
;
foreach
(
$files
as
$file
)
{
foreach
(
scandir
(
$templatePath
)
as
$file
)
{
if
(
is_file
(
$templatePath
.
'/'
.
$file
)
&&
CFileHelper
::
getExtension
(
$file
)
===
'php'
&&
$file
!==
'controller.php'
)
{
if
(
is_file
(
$templatePath
.
'/'
.
$file
)
&&
pathinfo
(
$file
,
PATHINFO_EXTENSION
)
===
'php'
)
{
$files
[]
=
new
CodeFile
(
$files
[]
=
new
CodeFile
(
"
$viewPath
/
$file
"
,
$this
->
render
(
"views/
$file
"
));
$this
->
viewPath
.
DIRECTORY_SEPARATOR
.
$file
,
$this
->
render
(
$templatePath
.
'/'
.
$file
)
);
}
}
}
}
if
(
$this
->
enableSearch
)
{
}
return
$files
;
return
$files
;
}
}
/**
* @return string the controller class name without the namespace part.
*/
public
function
getControllerClass
()
{
return
Inflector
::
id2camel
(
$this
->
getControllerID
())
.
'Controller'
;
}
/**
* @return string the controller ID (without the module ID prefix)
*/
public
function
getControllerID
()
{
if
((
$pos
=
strrpos
(
$this
->
controllerID
,
'/'
))
!==
false
)
{
return
substr
(
$this
->
controllerID
,
$pos
+
1
);
}
else
{
return
$this
->
controllerID
;
}
}
/**
* @return \yii\base\Module the module that the new controller belongs to
*/
public
function
getModule
()
{
if
((
$pos
=
strpos
(
$this
->
controllerID
,
'/'
))
!==
false
)
{
$id
=
substr
(
$this
->
controllerID
,
0
,
$pos
);
if
((
$module
=
Yii
::
$app
->
getModule
(
$id
))
!==
null
)
{
return
$module
;
}
}
return
Yii
::
$app
;
}
/**
* @return string the controller class file path
*/
public
function
getControllerFile
()
{
$module
=
$this
->
getModule
();
return
$module
->
getControllerPath
()
.
'/'
.
$this
->
getControllerClass
()
.
'.php'
;
}
/**
* @return string the action view file path
*/
public
function
getViewPath
()
{
$module
=
$this
->
getModule
();
return
$module
->
getViewPath
()
.
'/'
.
$this
->
getControllerID
()
;
}
}
}
framework/yii/gii/generators/crud/templates/views/index-grid.php
deleted
100644 → 0
View file @
3f2e7fa6
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php
echo
"<?php
\n
"
;
?>
/* @var $this
<?php
echo
$this
->
getControllerClass
();
?>
*/
/* @var $model
<?php
echo
$this
->
getModelClass
();
?>
*/
<?php
$label
=
$this
->
pluralize
(
$this
->
class2name
(
$this
->
modelClass
));
echo
"
\$
this->breadcrumbs=array(
'
$label
'=>array('index'),
'Manage',
);
\n
"
;
?>
$this->menu=array(
array('label'=>'List
<?php
echo
$this
->
modelClass
;
?>
', 'url'=>array('index')),
array('label'=>'Create
<?php
echo
$this
->
modelClass
;
?>
', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#
<?php
echo
$this
->
class2id
(
$this
->
modelClass
);
?>
-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>
Manage
<?php
echo
$this
->
pluralize
(
$this
->
class2name
(
$this
->
modelClass
));
?>
</h1>
<p>
You may optionally enter a comparison operator (
<b>
<
</b>
,
<b>
<
=
</b>
,
<b>
>
</b>
,
<b>
>
=
</b>
,
<b>
<>
</b>
or
<b>
=
</b>
) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php
echo
"<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>"
;
?>
<div
class=
"search-form"
style=
"display:none"
>
<?php
echo
"<?php
\$
this->renderPartial('_search',array(
'model'=>
\$
model,
)); ?>
\n
"
;
?>
</div>
<!-- search-form -->
<?php
echo
"<?php"
;
?>
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'
<?php
echo
$this
->
class2id
(
$this
->
modelClass
);
?>
-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
<?php
$count
=
0
;
foreach
(
$this
->
tableSchema
->
columns
as
$column
)
{
if
(
++
$count
==
7
)
echo
"
\t\t
/*
\n
"
;
echo
"
\t\t
'"
.
$column
->
name
.
"',
\n
"
;
}
if
(
$count
>=
7
)
echo
"
\t\t
*/
\n
"
;
?>
array(
'class'=>'CButtonColumn',
),
),
)); ?>
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