1

好的,所以基本上我已经使用 Kohana 创建了一个简单的页面,用于使用选项卡显示用户的消息收件箱/发件箱。

我的控制器是这样的:

$content                 = View::factory('messages')->bind('user', $user)->bind('received', $received)->bind('sent', $sent)->bind('pager_links', $pager_links);
$user                    = Auth::instance()->get_user();
$message_count           = ORM::factory('message')->where('to_id', '=', $user)->where('read', '=', '0')->count_all();
$pagination              = Pagination::factory(array(
    'total_items' => $message_count,
    'items_per_page' => 10
));
$received                = ORM::factory('messages')->where('messages.to_id', '=', $user)->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
$sent                    = ORM::factory('messages')->where('messages.user_id', '=', $user)->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
$pager_links             = $pagination->render();
$this->template->content = $content; 

到目前为止,我只在视图中显示收到的消息和分页,它工作正常。但是我想实现一个选项卡容器来在同一页面上显示接收和发送的项目。

我挠头想知道如何在不影响两个选项卡的情况下为每个选项卡使用分页方面。使用现有方法的最佳方向是什么?选择选项卡时,可能会在 URL 中添加一个附加参数...

谢谢

4

1 回答 1

1

基本上,您的问题是您不能page同时在两个选项卡的查询字符串中使用,因为显然它会影响两个分页功能。幸运的是,实际上有一个配置打开,允许您current page在查询字符串中指定参数的来源。

试试这个...

$pagination              = Pagination::factory(array(
    'current_page' => array('source' => 'query_string', 'key' => 'tab1_page'),
    'total_items' => $message_count,
    'items_per_page' => 10
));

然后,您需要做的就是确保您的分页视图将页码传递给查询字符串中的正确参数,例如http://mydomain.com/pagewithtabs?tab1_page=2&tab2_page=3将选项卡 1 放在第 2 页上,将选项卡 2 放在第 3 页上。

希望有帮助!

于 2012-11-18T11:41:14.943 回答