Skip to main content

Model::create

Execute Create Table

Description

public void Model::create( array $fields )

Arguments

NameData typeDefaultRemarks
$fieldsarrayFields information

Fields structure

KeyData typeRemarks
namestringColumn name
typestringColumn type
notnullbooleanEnable NOT NULL
dflt_valuemixedDefault value
pkbooleanEnable PRIMARY KEY
aibooleanEnable AUTOINCREMENT

Example

Controller
$model = new Model(true, array(
'table' => 'cms_news',
));

// CREATE TABLE cms_news(
// news_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
// title VARCHAR NOT NULL,
// body TEXT
// )
$model->create([
[
'name' => 'news_id',
'type' => 'INTEGER',
'notnull' => true,
'pk' => true,
'ai' => true,
],
[
'name' => 'title',
'type' => 'VARCHAR',
'notnull' => true,
],
[
'name' => 'body',
'type' => 'TEXT',
]
]);