メインコンテンツまでスキップ
Version: Fegg 5.x

Model::one

条件に合う最初の行を取得します

説明​

public array|null Model::one( [ array $options = [] ] )

条件に合う最初の行を連想配列で返します。合う行がなければnullを返します。どの行が最初になるかはorderで決まります。limitのオフセットも使います。

引数​

名前データ型デフォルト備考
$optionsarray[]array('select' => ...)でselectを上書きします

例​

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
}