OK so basically I have created a simple page using Kohana for displaying a user’s message inbox/outbox using tabs.
My controller is something like this:
$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;
So far I am only displaying the received messages and pagination in the view and it is working fine. However I want to implement a tab container to display both the received and sent items on the same page.
I am scratching my head wondering how to use the pagination aspect for each tab without it affecting both tabs. What would be the best direction for this using the existing approach? Perhaps throwing an additional parameter into the URL when a tab is selected…
Thanks
Basically your issue is that you can’t use
pagein the query string for both of the tabs at once, as obviously it will affect both pagination functions. Luckily there is in fact a configuration open that allows you to specify the source of thecurrent pageparameter in the query string.Try this…
Then all you need to do is make sure that your pagination view is passing the page number to the correct parameter in the query string e.g.
http://mydomain.com/pagewithtabs?tab1_page=2&tab2_page=3will put tab 1 on page 2 and tab 2 on page 3.Hope that helps!