Model::insert
Execute Insert data
Description
public string Model::insert( string $item, array $data )
Inserts one row and returns the new ID as a string. For new code, use insertRow: insert() writes '' for every column listed in $item that is missing from $data, and cannot store NULL.
$data is an associative array (values matched to $item by name) or a list (values in the order of $item). created, modified and valid are filled automatically and bind types are applied.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $item | string | Columns, separated by commas | |
| $data | array | Values |
Example
Controller
$model = new Model(true, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
$item = 'title, content';
$data = array(
'title' => 'Sample title',
'content' => 'Sample content',
);
// Returns the new ID
$insertedId = $model->insert($item, $data);
// -> '24'