Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created June 10, 2014 05:29
Show Gist options
  • Save memememomo/fb4e156620052f271577 to your computer and use it in GitHub Desktop.
Save memememomo/fb4e156620052f271577 to your computer and use it in GitHub Desktop.
ORM + Pagination で、ページネーションする ref: http://qiita.com/uchiko/items/b6a8a2f1ce8d3fe3cbf6
public function action_index()
{
// カテゴリ1の総数を取得する。
$query =
Model_User::query()->where('category_id', 1);
$total_items = $query->count();
// Paginationインスタンスを生成
$pagination = Pagination::forge('users', [
'total_items' => $total_items,
'per_page' => 20,
'uri_segment' => 'page',
]);
$stash['pagination'] = $pagination;
// 現在のページのユーザーのリストを取得
$stash['users'] =
$query
->order_by('created_by', 'desc')
->limit($pagination->per_page)
->offset($pagination->offset)
->get();
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment