infinitydevphp / yii2-table-builder
Yii2 table builder
dev-master
2016-09-19 15:55 UTC
Requires
- php: >=5.5.0
- yiisoft/yii2: >=2.0.6
This package is not auto-updated.
Last update: 2025-03-22 00:29:33 UTC
README
- Install
php composer.phar require infinitydevphp/yii2-table-builder "1.0"
Field config params
Param name | type | Description | Required |
---|---|---|---|
name | string | Field name in database | true |
type | string | One of definition type in yii\db\Schema | true |
length | integer | Length field for string numeric data | false |
default | mixed | Default value | false |
is_not_null | boolean | Is not null field | false |
unsigned | boolean | Unsigned number | false |
related_table | string | Related table name | false |
related_field | string | Related field name | false |
fk_name | string | Foreign key name | false |
Usages
- Create table
<?php use infinitydevphp\tableBuilder\TableBuilder; use \yii\db\Schema; $class = new TableBuilder([ 'tableName' => 'order', 'fields' => [ [ 'name' => 'id', 'type' => Schema::TYPE_PK, ], [ 'name' => 'date_created', 'type' => Schema::TYPE_TIMESTAMP, ], [ 'name' => 'price', 'type' => Schema::TYPE_INTEGER, ], [ 'name' => 'good_id', 'type' => Schema::TYPE_INTEGER, ], [ 'name' => 'user_id', 'type' => Schema::TYPE_INTEGER, 'length' => 11, 'related_field' => 'user_id', 'related_table' => 'order', ], ], ]); $resultRelations = $class->runQuery();
- Create migration from template
$class = new TableBuilderTemplateMigration([ 'tableName' => 'order' ]); $migrationTemplateString = $class->runQuery();