Anyone has any input on how to do pagination? Would be greatly appreciated!
use the pagination_helper (../lib/AkActionView/helpers/pagination_helper.php)
to get an instance of the Paginator
$this->mymodel_pages =& $this->pagination_helper->getPaginator($this->MyModel, $options));
$options could be: array('items_per_page'=>5);
to get the options for the finder
$find_options = $this->pagination_helper->getFindOptions($this->MyModel);
//now you can do:
$this->MyModel->find('all',$find_options);
in the View, you get "page"-links via
{mymodel_pages.links}
and could try:
<p>Thats page <?=$mymodel_pages->getCurrentPage() ?> of <?= $mymodel_pages->pages ?></p>
//=> Thats page 1 of 2.
Thanks a lot!
I have not tried this but you should be able to set extra url vars on
$this->mymodel_pages->_extraVars = array('key' => 'value');
$this->mymodel_pages holds an instance of AkPager which inherits from PEAR Pager_Common
well it seems, is not implemented, like you said it holds and instance but the access to that object is very limited. anyways if anyone want to know how to circunvent it, here it is: in AK_paginator:
class AK_Paginator
function &AkPaginator(&$controller, $item_count, $items_per_page, $current_page=1,$extraVars=array())
and in line 357:
'extraVars'=>$extraVars,
and in pagination_helper:
line 126 add:
,'extraVars' => array()
line 133 change:
$options['items_per_page'], @$this->_controller->params[$options['page_var_on_url']],$options['extraVars']);
now you can do this:
$this->product_pages = $this->pagination_helper->getPaginator($this->Product,
array('items_per_page' => 1,'extraVars' => array('category' => 'books')));
in case anyone is worried, i have not changed any normal behavior, just added a feature.
Hi Didrik,
As stated above, PEARs paginator can be user for non-conventional stuff.
Regarding the links, I would personally use javascript:history.back() or pass AK_URL value as a parameter on generated URLs
1 to 10 of 10