本文整理汇总了PHP中Phinx\Db\Table::addColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addColumn方法的具体用法?PHP Table::addColumn怎么用?PHP Table::addColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phinx\Db\Table
的用法示例。
在下文中一共展示了Table::addColumn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addColumn
/**
* You can pass `autoIncrement` as an option and it will be converted
* to the correct option for phinx to create the column with an
* auto increment attribute
*
* {@inheritdoc}
*/
public function addColumn($columnName, $type = null, $options = [])
{
if (isset($options['autoIncrement']) && $options['autoIncrement'] === true) {
$options['identity'] = true;
unset($options['autoIncrement']);
}
return parent::addColumn($columnName, $type, $options);
}
示例2: createSchemaTable
/**
* {@inheritdoc}
*/
public function createSchemaTable()
{
try {
$options = array('id' => false);
$table = new \Phinx\Db\Table($this->getSchemaTableName(), $options, $this);
$table->addColumn('version', 'biginteger', array('limit' => 14))->addColumn('start_time', 'timestamp')->addColumn('end_time', 'timestamp')->save();
} catch (\Exception $exception) {
throw new \InvalidArgumentException('There was a problem creating the schema table');
}
}
示例3: createSchemaTable
/**
* {@inheritdoc}
*/
public function createSchemaTable()
{
try {
$options = array('id' => false, 'primary_key' => 'version');
$table = new Table($this->getSchemaTableName(), $options, $this);
if ($this->getConnection()->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql' && version_compare($this->getConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.0', '>=')) {
$table->addColumn('version', 'biginteger', array('limit' => 14))->addColumn('start_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))->addColumn('end_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))->save();
} else {
$table->addColumn('version', 'biginteger')->addColumn('start_time', 'timestamp')->addColumn('end_time', 'timestamp')->save();
}
} catch (\Exception $exception) {
throw new \InvalidArgumentException('There was a problem creating the schema table: ' . $exception->getMessage());
}
}
示例4: testAddTableWithForeignKey
public function testAddTableWithForeignKey()
{
$this->mock->expects($this->any())->method('isValidColumnType')->with($this->callback(function ($column) {
return in_array($column->getType(), array('string', 'integer'));
}))->will($this->returnValue(true));
$table = new Table('table', array(), $this->adapter);
$table->addColumn('bar', 'string')->addColumn('relation', 'integer')->addForeignKey('relation', 'target_table', array('id'));
$this->mock->expects($this->once())->method('createTable')->with($this->callback(function ($table) {
if ($table->getName() !== 'pre_table_suf') {
throw new \Exception(sprintf('Table::getName was not prefixed/suffixed properly: "%s"', $table->getName()));
}
$fks = $table->getForeignKeys();
if (count($fks) !== 1) {
throw new \Exception(sprintf('Table::getForeignKeys count was incorrect: %d', count($fks)));
}
foreach ($fks as $fk) {
if ($fk->getReferencedTable()->getName() !== 'pre_target_table_suf') {
throw new \Exception(sprintf('ForeignKey::getReferencedTable was not prefixed/suffixed properly: "%s"', $fk->getReferencedTable->getName()));
}
}
return true;
}));
$table->create();
}
示例5: addColumn
/**
* Add a table column.
*
* Type can be: string, text, integer, float, decimal, datetime, timestamp,
* time, date, binary, boolean.
*
* Valid options can be: limit, default, null, precision or scale.
*
* @param string $columnName
* @param null $type
* @param array $options
*
* @return $this
*/
public function addColumn($columnName, $type = null, $options = [])
{
$this->table->addColumn($columnName, $type, $options);
return $this;
}