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
<?php
/**
* This is the template for generating the model class of a specified table.
*
* @var yii\web\View $this
* @var yii\gii\generators\model\Generator $generator
* @var string $tableName full table name
* @var string $className class name
* @var yii\db\TableSchema $tableSchema
* @var string[] $labels list of attribute labels (name=>label)
* @var string[] $rules list of validation rules
* @var array $relations list of relations (name=>relation declaration)
*/
echo "<?php\n";
?>
namespace <?= $generator->ns ?>;
/**
* This is the model class for table "<?= $tableName ?>".
*
<?php foreach ($tableSchema->columns as $column): ?>
* @property <?= "{$column->phpType} \${$column->name}\n" ?>
<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
<?php foreach ($relations as $name => $relation): ?>
* @property <?= $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n" ?>
<?php endforeach; ?>
<?php endif; ?>
*/
class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') . "\n" ?>
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '<?= $tableName ?>';
}
/**
* @inheritdoc
*/
public function rules()
{
return [<?= "\n\t\t\t" . implode(",\n\t\t\t", $rules) . "\n\t\t" ?>];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
<?php foreach ($labels as $name => $label): ?>
<?= "'$name' => '" . addslashes($label) . "',\n" ?>
<?php endforeach; ?>
];
}
<?php foreach ($relations as $name => $relation): ?>
/**
* @return \yii\db\ActiveRelation
*/
public function get<?= $name ?>()
{
<?= $relation[0] . "\n" ?>
}
<?php endforeach; ?>
}