Commit 7150524e by Qiang Xue

Finished model generator.

parent b968402e
......@@ -138,7 +138,7 @@ abstract class Schema extends Object
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name.
* @param boolean $refresh whether to fetch the latest available table schemas. If this is false,
* cached data may be returned if available.
* @return array the metadata for all tables in the database.
* @return TableSchema[] the metadata for all tables in the database.
* Each array element is an instance of [[TableSchema]] or its child class.
*/
public function getTableSchemas($schema = '', $refresh = false)
......@@ -161,7 +161,7 @@ abstract class Schema extends Object
* If not empty, the returned table names will be prefixed with the schema name.
* @param boolean $refresh whether to fetch the latest available table names. If this is false,
* table names fetched previously (if available) will be returned.
* @return array all table names in the database.
* @return string[] all table names in the database.
*/
public function getTableNames($schema = '', $refresh = false)
{
......
......@@ -4,18 +4,12 @@
*
* @var yii\base\View $this
* @var yii\gii\generators\model\Generator $generator
* @var string $tableName
* @var string $className
* @var string $tableName full table name
* @var string $className class name
* @var yii\db\TableSchema $tableSchema
* @var string[] $labels
* @var string[] $rules
*
* - $tableName: the table name for this class (prefix is already removed if necessary)
* - $modelClass: the model class name
* - $tableSchema: 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)
* @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";
......@@ -26,18 +20,22 @@ namespace <?php echo $generator->ns; ?>;
/**
* This is the model class for table "<?php echo $tableName; ?>".
*
* Attributes:
*
<?php foreach ($tableSchema->columns as $column): ?>
* @property <?php echo "{$column->phpType} \${$column->name}\n"; ?>
<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
<?php foreach ($relations as $name => $relation): ?>
* @property <?php echo $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n"; ?>
<?php endforeach; ?>
<?php endif; ?>
*/
class <?php echo $className; ?> extends <?php echo '\\' . ltrim($generator->baseClass, '\\') . "\n"; ?>
{
/**
* @inheritdoc
*/
public function tableName()
public static function tableName()
{
return '<?php echo $tableName; ?>';
}
......@@ -61,4 +59,14 @@ class <?php echo $className; ?> extends <?php echo '\\' . ltrim($generator->base
<?php endforeach; ?>
);
}
<?php foreach ($relations as $name => $relation): ?>
/**
* @return \yii\db\ActiveRelation
*/
public function get<?php echo $name; ?>()
{
<?php echo $relation[0] . "\n"; ?>
}
<?php endforeach; ?>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment