Jump to content

pagination is never easy


Recommended Posts

I'm having and always have a hard time building PaginatedArrays, I never know where to put the "limit=24" selector so please enlighten me.

Here's what I'm doing…

$categories = $page->protable('start=0, limit=999999'); // this I need in order to retrieve the pages's "categories" and I don't know how to make use of $rows instead for that purpose because of this confusing limit-API 

$rows = $page->protable; // put ("limit=20") here?
$custom = buildSelector($input, $rows); // this function returns an array of selectors depending on the user input

$items = new PaginatedArray; // or here?
// or here? $items->find("limit=20")
// or like this? $items("limit=20")
// or like this? $items = $items("limit=20")
// or like this? $items = $items->find("limit=20")

foreach ($rows as $r) :
    if ($custom->get('selector')->matches($r)) :

// or at this point?

and then

if ($items) { // or maybe somewhere here?
    echo '<span class="grey">'.$items->getPaginationString(array(
       'label' => 'entries',
       'zeroLabel' => '0 entries', // 3.0.127+ only
       'usePageNum' => false,
       'count' => count($items),
       'start' => $items->getStart(),
       'limit' => count($items),
       'total' => $items->getTotal()

and then of course…

$pager = $modules->get("MarkupPagerNav");
echo '<div class="uk-flex uk-flex-center">'.$pager->render($items, $options).'</div>';

I'm out of ideas and confused cause it doesn't make sense to me either way.


The buildSelector function above returns and array…

$selected = new Selectors("$letter, $searchterm, $category");
$custom = new Wirearray;
$custom->set('selector', $selected);
$built->set('sort', $sort);
return $custom;

and each of the new selectors are basically strings ("category=whatever")

Also, you cannot put the "sort=title" or whatever as a selector for the Selectors function (see above). Why, I know not.

I don't know if that is the proper way but selecting kind of works now as opposed to many other ways I tried. Selectors always require a lot of trial and error, it seems to have a very sensitive API, always depends on double quotes, single quotes and how you concatenate.

Thanks for help!

Link to comment
Share on other sites

  • 5 months later...

OK so I guess it doesn't make more sense to anyone else out here either. Every time I try to use pagination I spend hours guessing and trying and when I get it to work, I'm back to where I started and I'm not one bit smarter than before because when at the time I will use pagination again, it might be a slightly different scenario that also will require hours of guessing.

Here's what I'm trying now (for a different project)

$start = $limit * ($input->pageNum() - 1);

$allcasts = pages("template=cast"); // first store in in-memory db? 
$casts = $allcasts->find("has_parent=$page, sort=$sort"); // then find in in-memory db?
$casts = sortOutEmpty($casts, $decider);

// I use $decider as a variable so I can dynamically set a field that 
// depending if it's empty or not 
// decides whether the page should be displayed in the current language or not

function sortOutEmpty($items, $decider) {
    $casts = new PaginatedArray;
    foreach ($items as $item) :
        if ($item->$decider != '') :
    return $casts;

The above doesn't work. I understand I need to set the "total" for the array but like I said, I never know how to do that properly. 

Thanks for help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...