【发布时间】:2013-09-20 13:07:27
【问题描述】:
我正在尝试在 kohana 中集成分页,但不知道如何集成它。以下是控制器功能
public function action_index() {
//setup the model and view
$_users = Model::factory('users');
$us = $_users->get_users();
$view = View::factory('users/index')->bind('user_list', $us);
$this->template->set('content',$view);
}
如何在此功能中添加分页? 我找到了一些分页代码,但无法集成。这是我找到的函数
$this->pagination = new Pagination(array(
'base_url' => 'users/index/',
'uri_segment' => 'page',
'total_items' => count($items->get_item_count())
请帮帮我
编辑: 我尝试了类似
public function action_index(){
$query = DB::select()->from('user');
// count number of users
$total_users = count($query);;
// set-up the pagination
$pagination = Pagination::factory(array(
'total_items' => $total_users,
'items_per_page' => 10, // this will override the default set in your config
));
// select rows using pagination's limit&offset
$users = $query->offset($pagination->offset)->limit($pagination->items_per_page)->execute();
$view = View::factory('users/index')->bind('user_list', $users)->bind('pagination', $pagination);
$this->template->set('content',$view);
}
现在没有发现错误,但没有显示分页。使用了 @DanielThompson 建议的 shadowhand 的分页模块
【问题讨论】:
-
找到此文档kohanaframework.org/3.0/guide/api/Pagination。任何人都可以举一些例子
-
您使用的是哪个版本的 Kohana?
-
我正在使用 kohana 3.3.1
标签: pagination kohana kohana-3