Model::one
Get the first matching row
Description
public array|null Model::one( [ array $options = [] ] )
Returns the first matching row as an associative array, or null when nothing matches. order decides which row is first; the offset of limit is used.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $options | array | [] | array('select' => ...) overrides select |
Example
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
// The newest news, or null
$latest = $model->order('post_date', 'desc')->one();
$record = $model->where('title = ?', $title)->one();
if ($record === null) {
// not found
}