Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorprtscr
     

    Anyone has any input on how to do pagination? Would be greatly appreciated!

    • CommentAuthorKaste
     

    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.
    
    • CommentAuthorprtscr
     

    Thanks a lot!

    • CommentAuthorinsanet
     
    and how do you add parameters to {mymodel_pages.links}? to pass a variable in every paginator link
    •  
      CommentAuthorbermi
     

    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

    • CommentAuthorinsanet
     
    hey bermi, its not working, doesnt add anything to the links, but its no throwing errors neither. another work around?

    and i just took a look to the library in AK_Pager 317:

    //'extraVars'=>'',//additional URL vars to be added to the querystring.

    is commented, i uncommented it and is throwing errors, something with array_merge()
    ------------edit-------------

    ok i changed it to:
    'extraVars' => array();
    and is working, i tested it with params and is working too. i just need to access this, without changing the libraries. i will keep looking...
    • CommentAuthorinsanet
     

    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.

    • CommentAuthordpinte
     
    Is there a way to do some pagination using a custom list of objects.

    I would like to have a listing page that has a list of id's of contacts (linked to my Contact model) as input (the search condition that made the list of contact is too complex to be passed to the page). Thus, i'm there with a list of id's of contacts and wish to have some pagination around that. Do you have a way to do that ?

    Other question : I have a first set of pagination on the full list of contacts. The user can select a contact to have the full details on it. I would like to a have link back that comes back to the very same paginated view that the user left before showing the contact. How can I do that ? Passing the contact number to the show action and then create a link with enough information for the paginator ?

    Thanks for your help.

    Didrik
    •  
      CommentAuthorbermi
     

    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

    • CommentAuthordpinte
     
    Just for future reference, here is the link to the PEAR Page doc : http://pear.php.net/manual/en/package.html.pager.php

    Thanks for the quick answer.

    Didrik