Pagination with PageList model

Permalink 4 users found helpful
Working on pagination my PageList model. Currently its pagination the items however I'm having a tough time figuring out the rest of the methods for Prev, Next, Current. All the functions that PaginationHelper does.

On my single_page:
<?php
Loader::model('transactions_list');
$tl = new TransactionsPageList;
if($tl->getSummary()->pages > 1) {
        $tl->getPaginiation();
}
?>
<div class="paging">
   <ul>
      <li><a href="#" class="prev">prev</a></li>
      <li><a href="#"><?php echo $tl->getCurrentPage(); ?></a></li>
      <li>of</li>
      <li>4</li>
      <li><a href="#" class="next">next</a></li>
   </ul>


In my PageList Model:
<?php
   defined('C5_EXECUTE') or die("Access Denied.");
   Loader::model('page_list');
   class TransactionsPageList extends PageList {
      public function __construct(){
         $this->filterByParentID(183);
         $this->sortByDisplayOrder();
         $this->setItemsPerPage(2);
       }
       public function filterBy($filter=null){
          if($filter == null || $filter == 'ALL') {
             return;
          } else {
              $this->filterByAttribute('sectors', '%'.$filter.'%', 'like');
           }


Do I need to use the PaginationHelper? How would I implement it in my current code?

Thanks!

travisneids
 
travisneids replied on at Permalink Reply
travisneids
Still struggling. Any help would be awesome!
mkly replied on at Permalink Best Answer Reply
mkly
I'm having a little trouble understanding a specific question, but maybe this helps. People typically do paging by passing the page list to the view with
//in controller
$page_list = new PageList();
$page_list->filterByAllKindsOfStuff('blah');
$pages = $page_list->getPage();
$this->set('page_list', $page_list);
$this->set('pages', $pages);

Then in your view you throw this in
//in view
$page_list->displayPaging();


If you are trying to roll your own a bit
//in controller
$page_list = new PageList();
$page_list->filterByAllKindsOfStuff('blah');
$pages = $page_list->getPage();
// This returns a pagination helper object
$pagination = $page_list->getPagination();
$this->set('page_list', $page_list);
$this->set('pages', $pages);
$this->set('pagination', $page_list);

//in view
<div class="paging">
  <ul>
    // There are other things you can do.
    // See the PaginationHelper class
    <li><?php echo $pagination->getPrevious('< prev') ?></li>
    <li><?php echo $pagination->getCurrentPage() ?></li>
    <li><?php echo $pagination->getNext('next >') ?></li>
  </ul>
</div>
travisneids replied on at Permalink Reply
travisneids
Ah I was so close! You are the man! Thanks as always mkly!