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
dccb10d1
Commit
dccb10d1
authored
Aug 20, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
model generator WIP
parent
a65be3b1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
176 additions
and
1 deletion
+176
-1
gii.js
framework/yii/gii/assets/gii.js
+1
-1
Generator.php
framework/yii/gii/generators/model/Generator.php
+0
-0
model.php
framework/yii/gii/generators/model/templates/model.php
+163
-0
form.php
framework/yii/gii/generators/model/views/form.php
+12
-0
No files found.
framework/yii/gii/assets/gii.js
View file @
dccb10d1
...
...
@@ -14,7 +14,7 @@ yii.gii = (function ($) {
};
var
initStickyInputs
=
function
()
{
$
(
'.sticky:not(.error) input,select,textarea'
).
each
(
function
()
{
$
(
'.sticky:not(.error) input
[type="text"]
,select,textarea'
).
each
(
function
()
{
var
value
;
if
(
this
.
tagName
===
'SELECT'
)
{
value
=
this
.
options
[
this
.
selectedIndex
].
text
;
...
...
framework/yii/gii/generators/model/Generator.php
View file @
dccb10d1
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/model/templates/model.php
0 → 100644
View file @
dccb10d1
<?php
/**
* This is the template for generating the model class of a specified table.
* - $this: the ModelCode object
* - $tableName: the table name for this class (prefix is already removed if necessary)
* - $modelClass: the model class name
* - $columns: list of table columns (name=>CDbColumnSchema)
* - $labels: list of attribute labels (name=>label)
* - $rules: list of validation rules
* - $relations: list of relations (name=>relation declaration)
*/
?>
<?php
echo
"<?php
\n
"
;
?>
/**
* This is the model class for table "
<?php
echo
$tableName
;
?>
".
*
* The followings are the available columns in table '
<?php
echo
$tableName
;
?>
':
<?php
foreach
(
$columns
as
$column
)
:
?>
* @property
<?php
echo
$column
->
type
.
' $'
.
$column
->
name
.
"
\n
"
;
?>
<?php
endforeach
;
?>
<?php
if
(
!
empty
(
$relations
))
:
?>
*
* The followings are the available model relations:
<?php
foreach
(
$relations
as
$name
=>
$relation
)
:
?>
* @property
<?php
if
(
preg_match
(
"~^array\(self::([^,]+), '([^']+)', '([^']+)'\)$~"
,
$relation
,
$matches
))
{
$relationType
=
$matches
[
1
];
$relationModel
=
$matches
[
2
];
switch
(
$relationType
){
case
'HAS_ONE'
:
echo
$relationModel
.
' $'
.
$name
.
"
\n
"
;
break
;
case
'BELONGS_TO'
:
echo
$relationModel
.
' $'
.
$name
.
"
\n
"
;
break
;
case
'HAS_MANY'
:
echo
$relationModel
.
'[] $'
.
$name
.
"
\n
"
;
break
;
case
'MANY_MANY'
:
echo
$relationModel
.
'[] $'
.
$name
.
"
\n
"
;
break
;
default
:
echo
'mixed $'
.
$name
.
"
\n
"
;
}
}
?>
<?php
endforeach
;
?>
<?php
endif
;
?>
*/
class
<?php
echo
$modelClass
;
?>
extends
<?php
echo
$this
->
baseClass
.
"
\n
"
;
?>
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return '
<?php
echo
$tableName
;
?>
';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
<?php
foreach
(
$rules
as
$rule
)
:
?>
<?php
echo
$rule
.
",
\n
"
;
?>
<?php
endforeach
;
?>
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('
<?php
echo
implode
(
', '
,
array_keys
(
$columns
));
?>
', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
<?php
foreach
(
$relations
as
$name
=>
$relation
)
:
?>
<?php
echo
"'
$name
' =>
$relation
,
\n
"
;
?>
<?php
endforeach
;
?>
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
<?php
foreach
(
$labels
as
$name
=>
$label
)
:
?>
<?php
echo
"'
$name
' => '
$label
',
\n
"
;
?>
<?php
endforeach
;
?>
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
<?php
foreach
(
$columns
as
$name
=>
$column
)
{
if
(
$column
->
type
===
'string'
)
{
echo
"
\t\t\$
criteria->compare('
$name
',
\$
this->
$name
,true);
\n
"
;
}
else
{
echo
"
\t\t\$
criteria->compare('
$name
',
\$
this->
$name
);
\n
"
;
}
}
?>
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
<?php
if
(
$connectionId
!=
'db'
)
:?>
/**
* @return CDbConnection the database connection used for this class
*/
public
function
getDbConnection
()
{
return
Yii
::
app
()
-><?
php
echo
$connectionId
?>
;
}
<?php
endif
?>
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return
<?php
echo
$modelClass
;
?>
the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
framework/yii/gii/generators/model/views/form.php
0 → 100644
View file @
dccb10d1
<?php
/**
* @var yii\base\View $this
* @var yii\widgets\ActiveForm $form
* @var yii\gii\generators\form\Generator $generator
*/
echo
$form
->
field
(
$generator
,
'tableName'
);
echo
$form
->
field
(
$generator
,
'modelClass'
);
echo
$form
->
field
(
$generator
,
'baseClass'
);
echo
$form
->
field
(
$generator
,
'buildRelations'
)
->
checkbox
();
echo
$form
->
field
(
$generator
,
'commentsAsLabels'
)
->
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