PHP Class yii\gii\generators\model\Generator

Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\gii\Generator
Show file Open project: yiisoft/yii2-gii Class Usage Examples

Public Properties

Property Type Description
$baseClass
$db
$generateLabelsFromComments
$generateQuery
$generateRelations
$generateRelationsFromCurrentSchema
$modelClass
$ns
$queryBaseClass
$queryClass
$queryNs
$tableName
$useSchemaName
$useTablePrefix

Protected Properties

Property Type Description
$classNames
$tableNames

Public Methods

Method Description
attributeLabels ( )
autoCompleteData ( )
generate ( )
generateLabels ( yii\db\TableSchema $table ) : array Generates the attribute labels for the specified table.
generateRules ( yii\db\TableSchema $table ) : array Generates validation rules for the specified table.
generateTableName ( string $tableName ) : string Generates the table name by considering table prefix.
getDescription ( )
getName ( )
getTablePrefix ( ) : string Returns the tablePrefix property of the DB connection as specified
hints ( )
requiredTemplates ( )
rules ( )
stickyAttributes ( )
validateDb ( ) Validates the [[db]] attribute.
validateModelClass ( ) Validates the [[modelClass]] attribute.
validateNamespace ( string $attribute ) Validates the namespace.
validateTableName ( ) Validates the [[tableName]] attribute.

Protected Methods

Method Description
addInverseRelations ( array $relations ) : array Adds inverse relations
checkJunctionTable ( $table ) : array | boolean Checks if the given table is a junction table, that is it has at least one pair of unique foreign keys.
generateClassName ( string $tableName, boolean $useSchemaName = null ) : string Generates a class name from the specified table name.
generateQueryClassName ( string $modelClassName ) : string Generates a query class name from the specified model class name.
generateRelationLink ( array $refs ) : string Generates the link parameter to be used in generating the relation declaration.
generateRelationName ( array $relations, yii\db\TableSchema $table, string $key, boolean $multiple ) : string Generate a relation name for the specified table and a base name.
generateRelations ( ) : array
getDbConnection ( ) : Connection
getSchemaNames ( ) : string[]
getTableNames ( ) : array
isColumnAutoIncremental ( yii\db\TableSchema $table, array $columns ) : boolean Checks if any of the specified columns is auto incremental.
isHasManyRelation ( yii\db\TableSchema $table, array $fks ) : boolean Determines if relation is of has many type

Private Methods

Method Description
generateManyManyRelations ( $table, array $fks, array $relations ) : array Generates relations using a junction table by adding an extra viaTable().

Method Details

addInverseRelations() protected method

Adds inverse relations
Since: 2.0.5
protected addInverseRelations ( array $relations ) : array
$relations array relation declarations
return array relation declarations extended with inverse relation names

attributeLabels() public method

public attributeLabels ( )

autoCompleteData() public method

public autoCompleteData ( )

checkJunctionTable() protected method

Checks if the given table is a junction table, that is it has at least one pair of unique foreign keys.
protected checkJunctionTable ( $table ) : array | boolean
return array | boolean all unique foreign key pairs if the table is a junction table, or false if the table is not a junction table.

generate() public method

public generate ( )

generateClassName() protected method

Generates a class name from the specified table name.
protected generateClassName ( string $tableName, boolean $useSchemaName = null ) : string
$tableName string the table name (which may contain schema prefix)
$useSchemaName boolean should schema name be included in the class name, if present
return string the generated class name

generateLabels() public method

Generates the attribute labels for the specified table.
public generateLabels ( yii\db\TableSchema $table ) : array
$table yii\db\TableSchema the table schema
return array the generated attribute labels (name => label)

generateQueryClassName() protected method

Generates a query class name from the specified model class name.
protected generateQueryClassName ( string $modelClassName ) : string
$modelClassName string model class name
return string generated class name

generateRelationName() protected method

Generate a relation name for the specified table and a base name.
protected generateRelationName ( array $relations, yii\db\TableSchema $table, string $key, boolean $multiple ) : string
$relations array the relations being generated currently.
$table yii\db\TableSchema the table schema
$key string a base name that the relation name may be generated from
$multiple boolean whether this is a has-many relation
return string the relation name

generateRelations() protected method

protected generateRelations ( ) : array
return array the generated relation declarations

generateRules() public method

Generates validation rules for the specified table.
public generateRules ( yii\db\TableSchema $table ) : array
$table yii\db\TableSchema the table schema
return array the generated validation rules

generateTableName() public method

If [[useTablePrefix]] is false, the table name will be returned without change.
public generateTableName ( string $tableName ) : string
$tableName string the table name (which may contain schema prefix)
return string the generated table name

getDbConnection() protected method

protected getDbConnection ( ) : Connection
return yii\db\Connection the DB connection as specified by [[db]].

getDescription() public method

public getDescription ( )

getName() public method

public getName ( )

getSchemaNames() protected method

Since: 2.0.5
protected getSchemaNames ( ) : string[]
return string[] all db schema names or an array with a single empty string

getTableNames() protected method

protected getTableNames ( ) : array
return array the table names that match the pattern specified by [[tableName]].

getTablePrefix() public method

Returns the tablePrefix property of the DB connection as specified
See also: getDbConnection
Since: 2.0.5
public getTablePrefix ( ) : string
return string

hints() public method

public hints ( )

isColumnAutoIncremental() protected method

Checks if any of the specified columns is auto incremental.
protected isColumnAutoIncremental ( yii\db\TableSchema $table, array $columns ) : boolean
$table yii\db\TableSchema the table schema
$columns array columns to check for autoIncrement property
return boolean whether any of the specified columns is auto incremental.

isHasManyRelation() protected method

Determines if relation is of has many type
Since: 2.0.5
protected isHasManyRelation ( yii\db\TableSchema $table, array $fks ) : boolean
$table yii\db\TableSchema
$fks array
return boolean

requiredTemplates() public method

public requiredTemplates ( )

rules() public method

public rules ( )

stickyAttributes() public method

public stickyAttributes ( )

validateDb() public method

Validates the [[db]] attribute.
public validateDb ( )

validateModelClass() public method

Validates the [[modelClass]] attribute.
public validateModelClass ( )

validateNamespace() public method

Validates the namespace.
public validateNamespace ( string $attribute )
$attribute string Namespace variable.

validateTableName() public method

Validates the [[tableName]] attribute.
public validateTableName ( )

Property Details

$baseClass public property

public $baseClass

$classNames protected property

protected $classNames

$db public property

public $db

$generateLabelsFromComments public property

public $generateLabelsFromComments

$generateQuery public property

public $generateQuery

$generateRelations public property

public $generateRelations

$generateRelationsFromCurrentSchema public property

public $generateRelationsFromCurrentSchema

$modelClass public property

public $modelClass

$ns public property

public $ns

$queryBaseClass public property

public $queryBaseClass

$queryClass public property

public $queryClass

$queryNs public property

public $queryNs

$tableName public property

public $tableName

$tableNames protected property

protected $tableNames

$useSchemaName public property

public $useSchemaName

$useTablePrefix public property

public $useTablePrefix