Model::limit
行数を制限します
説明
public self Model::limit( int $count, [ int $offset = 0 ] )
all、column、toSqlにLIMITを付けます。one、value、existsはオフセットを使います。countは無視します。findは代わりにlistMaxとcurrentでページングし、limit()を設定しているとLogicExceptionを投げます。
$countが1未満、または$offsetが0未満の場合はInvalidArgumentExceptionを投げます。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $count | int | 最大の行数 | |
| $offset | int | 0 | 読み飛ばす行数 |
例
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
// The 5 newest
$records = $model->order('post_date', 'desc')->limit(5)->all();
// The next 5 (rows 6 to 10)
$records = $model->order('post_date', 'desc')->limit(5, 5)->all();