index.php
5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
$class=get_class($model);
Yii::app()->clientScript->registerScript('gii.model',"
$('#{$class}_connectionId').change(function(){
var tableName=$('#{$class}_tableName');
tableName.autocomplete('option', 'source', []);
$.ajax({
url: '".Yii::app()->getUrlManager()->createUrl('gii/model/getTableNames')."',
data: {db: this.value},
dataType: 'json'
}).done(function(data){
tableName.autocomplete('option', 'source', data);
});
});
$('#{$class}_modelClass').change(function(){
$(this).data('changed',$(this).val()!='');
});
$('#{$class}_tableName').bind('keyup change', function(){
var model=$('#{$class}_modelClass');
var tableName=$(this).val();
if(tableName.substring(tableName.length-1)!='*') {
$('.form .row.model-class').show();
}
else {
$('#{$class}_modelClass').val('');
$('.form .row.model-class').hide();
}
if(!model.data('changed')) {
var i=tableName.lastIndexOf('.');
if(i>=0)
tableName=tableName.substring(i+1);
var tablePrefix=$('#{$class}_tablePrefix').val();
if(tablePrefix!='' && tableName.indexOf(tablePrefix)==0)
tableName=tableName.substring(tablePrefix.length);
var modelClass='';
$.each(tableName.split('_'), function() {
if(this.length>0)
modelClass+=this.substring(0,1).toUpperCase()+this.substring(1);
});
model.val(modelClass);
}
});
$('.form .row.model-class').toggle($('#{$class}_tableName').val().substring($('#{$class}_tableName').val().length-1)!='*');
");
?>
<h1>Model Generator</h1>
<p>This generator generates a model class for the specified database table.</p>
<?php $form=$this->beginWidget('CCodeForm', array('model'=>$model)); ?>
<div class="row sticky">
<?php echo $form->labelEx($model, 'connectionId')?>
<?php echo $form->textField($model, 'connectionId', array('size'=>65))?>
<div class="tooltip">
The database component that should be used.
</div>
<?php echo $form->error($model,'connectionId'); ?>
</div>
<div class="row sticky">
<?php echo $form->labelEx($model,'tablePrefix'); ?>
<?php echo $form->textField($model,'tablePrefix', array('size'=>65)); ?>
<div class="tooltip">
This refers to the prefix name that is shared by all database tables.
Setting this property mainly affects how model classes are named based on
the table names. For example, a table prefix <code>tbl_</code> with a table name <code>tbl_post</code>
will generate a model class named <code>Post</code>.
<br/>
Leave this field empty if your database tables do not use common prefix.
</div>
<?php echo $form->error($model,'tablePrefix'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'tableName'); ?>
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'model'=>$model,
'attribute'=>'tableName',
'name'=>'tableName',
'source'=>Yii::app()->hasComponent($model->connectionId) ? array_keys(Yii::app()->{$model->connectionId}->schema->getTables()) : array(),
'options'=>array(
'minLength'=>'0',
'focus'=>new CJavaScriptExpression('function(event,ui) {
$("#'.CHtml::activeId($model,'tableName').'").val(ui.item.label);
return false;
}')
),
'htmlOptions'=>array(
'id'=>'ModelCode_tableName',
'size'=>'65'
),
)); ?>
<div class="tooltip">
This refers to the table name that a new model class should be generated for
(e.g. <code>tbl_user</code>). It can contain schema name, if needed (e.g. <code>public.tbl_post</code>).
You may also enter <code>*</code> (or <code>schemaName.*</code> for a particular DB schema)
to generate a model class for EVERY table.
</div>
<?php echo $form->error($model,'tableName'); ?>
</div>
<div class="row model-class">
<?php echo $form->label($model,'modelClass',array('required'=>true)); ?>
<?php echo $form->textField($model,'modelClass', array('size'=>65)); ?>
<div class="tooltip">
This is the name of the model class to be generated (e.g. <code>Post</code>, <code>Comment</code>).
It is case-sensitive.
</div>
<?php echo $form->error($model,'modelClass'); ?>
</div>
<div class="row sticky">
<?php echo $form->labelEx($model,'baseClass'); ?>
<?php echo $form->textField($model,'baseClass',array('size'=>65)); ?>
<div class="tooltip">
This is the class that the new model class will extend from.
Please make sure the class exists and can be autoloaded.
</div>
<?php echo $form->error($model,'baseClass'); ?>
</div>
<div class="row sticky">
<?php echo $form->labelEx($model,'modelPath'); ?>
<?php echo $form->textField($model,'modelPath', array('size'=>65)); ?>
<div class="tooltip">
This refers to the directory that the new model class file should be generated under.
It should be specified in the form of a path alias, for example, <code>application.models</code>.
</div>
<?php echo $form->error($model,'modelPath'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'buildRelations'); ?>
<?php echo $form->checkBox($model,'buildRelations'); ?>
<div class="tooltip">
Whether relations should be generated for the model class.
In order to generate relations, full scan of the whole database is needed.
You should disable this option if your database contains too many tables.
</div>
<?php echo $form->error($model,'buildRelations'); ?>
</div>
<?php $this->endWidget(); ?>