Model::find
Get one page of rows
Description
public array Model::find( [ array $options = [] ] )
Returns one page of matching rows (an array of associative arrays; an empty array when nothing matches). The page size is set with listMax (default 10) and the page with current. find() counts the matching rows first, so getPager can return the page links afterwards.
To get every row without paging, use all. find() throws LogicException when limit was set.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $options | array | [] | Overrides select, list_max and current |
Options
| Key | Remarks |
|---|---|
select | Same as select |
list_max | Same as listMax |
current | Same as current |
Any other key throws an Exception.
Example
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
$this->page['data'] = $model
->where('category = ?', 2)
->order('post_date', 'desc')
->listMax(20)
->current($this->in('p'))
->find();
$this->page['pager'] = $model->getPager();
// Same as listMax(20)->current($this->in('p'))
$records = $model->find(array('list_max' => 20, 'current' => $this->in('p')));