Created
June 10, 2014 05:29
-
-
Save memememomo/fb4e156620052f271577 to your computer and use it in GitHub Desktop.
ORM + Pagination で、ページネーションする ref: http://qiita.com/uchiko/items/b6a8a2f1ce8d3fe3cbf6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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