本文整理汇总了PHP中yii\db\Migration::addColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::addColumn方法的具体用法?PHP Migration::addColumn怎么用?PHP Migration::addColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Migration
的用法示例。
在下文中一共展示了Migration::addColumn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addColumn
/**
* @inheritdoc
* Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
*/
public function addColumn($table, $column, $type)
{
$table = $this->autoWrappedTableName($table);
return parent::addColumn($table, $column, $type);
}
示例2: addColumn
/**
* @inheritdoc
*/
public function addColumn($table, $column, $type)
{
parent::addColumn($table, $column, $this->fixColumnType($type));
}
示例3: afterSave
/**
* @param bool $insert
* @param array $changedAttributes
* @return bool
*/
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if (!in_array($this->scenario, ['update', 'create'])) {
return true;
}
$cm = $this->cm;
$mg = new Migration();
$table = Cm::$TAB_PREFIX[$cm->tab_index] . $cm->tab;
$column = null;
$type = $this->data_type;
switch ($type) {
case 'integer':
case 'smallInteger':
case 'boolean':
case 'float':
case 'double':
$column = $mg->{$type}()->notNull()->defaultValue(0);
break;
case 'string':
$column = $mg->{$type}($this->length)->notNull()->defaultValue('');
break;
case 'decimal':
$column = $mg->{$type}($this->length)->notNull()->defaultValue(0);
break;
default:
$column = $mg->{$type}()->defaultValue(null);
break;
}
$column .= " COMMENT '" . $this->label . "'";
if ($insert) {
$mg->addColumn('{{%' . $table . '}}', $this->name, $column);
} else {
$oldName = $this->old_name;
$newname = $this->name;
if ($oldName !== $newname) {
$mg->renameColumn('{{%' . $table . '}}', $oldName, $newname);
}
$mg->alterColumn('{{%' . $table . '}}', $newname, $column);
}
return true;
}
示例4: addColumn
public function addColumn($tableName, $column, $type)
{
$table = Yii::$app->db->schema->getTableSchema($tableName);
if (!isset($table->columns[$column])) {
parent::addColumn($tableName, $column, $type);
}
}
示例5: addColumn
public function addColumn($table, $column, $type)
{
if ($type instanceof ForeignKeyColumn) {
parent::addColumn($table, $column, $this->integer());
$type->migrate = $this;
$type->sourceTable($table);
$type->sourceColumn($column);
$type->apply();
} else {
return parent::addColumn($table, $column, $type);
}
}
示例6: addColumns
/**
* Add multiple columns to a table
* @param string $table
* @param array $columns ["column_name"=>type]
*/
public function addColumns($table, $columns)
{
foreach ($columns as $column => $type) {
parent::addColumn($table, $column, $type);
}
}