メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Model::limit

Cap the number of rows

Description​

public self Model::limit( int $count, [ int $offset = 0 ] )

Adds LIMIT to all, column and toSql; one, value and exists use the offset. count ignores it. find pages with listMax and current instead and throws LogicException when limit() was set.

Throws InvalidArgumentException when $count is under 1 or $offset under 0.

Arguments​

NameData typeDefaultRemarks
$countintMaximum number of rows
$offsetint0Number of rows to skip

Example​

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();