You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 line
2.1KB

  1. <?php
  2. /**
  3. * This is the template for generating the model class of a specified table.
  4. */
  5. /* @var $this yii\web\View */
  6. /* @var $generator yii\gii\generators\model\Generator */
  7. /* @var $tableName string full table name */
  8. /* @var $className string class name */
  9. /* @var $tableSchema yii\db\TableSchema */
  10. /* @var $labels string[] list of attribute labels (name => label) */
  11. /* @var $rules string[] list of validation rules */
  12. /* @var $relations array list of relations (name => relation declaration) */
  13. echo "<?php\n";
  14. ?>
  15. namespace <?= $generator->ns ?>;
  16. use Yii;
  17. /**
  18. * This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
  19. *
  20. <?php foreach ($tableSchema->columns as $column): ?>
  21. * @property <?= "{$column->phpType} \${$column->name}\n" ?>
  22. <?php endforeach; ?>
  23. <?php if (!empty($relations)): ?>
  24. *
  25. <?php foreach ($relations as $name => $relation): ?>
  26. * @property <?= $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n" ?>
  27. <?php endforeach; ?>
  28. <?php endif; ?>
  29. */
  30. class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') . "\n" ?>
  31. {
  32. /**
  33. * @inheritdoc
  34. */
  35. public static function tableName()
  36. {
  37. return '<?= $generator->generateTableName($tableName) ?>';
  38. }
  39. <?php if ($generator->db !== 'db'): ?>
  40. /**
  41. * @return \yii\db\Connection the database connection used by this AR class.
  42. */
  43. public static function getDb()
  44. {
  45. return Yii::$app->get('<?= $generator->db ?>');
  46. }
  47. <?php endif; ?>
  48. /**
  49. * @inheritdoc
  50. */
  51. public function rules()
  52. {
  53. return [<?= "\n " . implode(",\n ", $rules) . "\n " ?>];
  54. }
  55. /**
  56. * @inheritdoc
  57. */
  58. public function attributeLabels()
  59. {
  60. return [
  61. <?php foreach ($labels as $name => $label): ?>
  62. <?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
  63. <?php endforeach; ?>
  64. ];
  65. }
  66. <?php foreach ($relations as $name => $relation): ?>
  67. /**
  68. * @return \yii\db\ActiveQuery
  69. */
  70. public function get<?= $name ?>()
  71. {
  72. <?= $relation[0] . "\n" ?>
  73. }
  74. <?php endforeach; ?>
  75. }