Model::create
Execute Create Table
Description
public void Model::create( array $fields )
Arguments
Name | Data type | Default | Remarks |
---|---|---|---|
$fields | array | Fields information |
Fields structure
Key | Data type | Remarks |
---|---|---|
name | string | Column name |
type | string | Column type |
notnull | boolean | Enable NOT NULL |
dflt_value | mixed | Default value |
pk | boolean | Enable PRIMARY KEY |
ai | boolean | Enable 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',
]
]);