Model::find
1ページ分の行を取得します
説明
public array Model::find( [ array $options = [] ] )
条件に合う行のうち1ページ分を返します(連想配列の配列。合う行がなければ空の配列)。1ページの件数はlistMax(デフォルトは10)で、ページはcurrentで指定します。find()は先に条件に合う行数を数えるので、そのあとgetPagerでページャーの情報を取得できます。
ページングせずにすべての行を取るときはallを使います。limitを設定していると、find()はLogicExceptionを投げます。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $options | array | [] | select、list_max、currentを上書きします |
オプション
| キー | 備考 |
|---|---|
select | selectと同じ |
list_max | listMaxと同じ |
current | currentと同じ |
ほかのキーを渡すとExceptionを投げます。
例
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')));