PageList's get() function's limit doesn't work

Permalink
I'm trying to do something as simple as:

$home_slider = Core::Make('PageList');
$home_slider = new PageList();
$home_slider->sortByPublicDateDescending();
$home_slider->filterByAttribute("is_featured",1);
$pages = $home_slider->get(4);
foreach($pages as $page):
// bla bla
endforeach;


Unfortunately, I'm getting all the pages that have the is_featured attribute instead of just 4. What am I missing here?

VPenkov
 
VPenkov replied on at Permalink Reply
VPenkov
Okay, I sorta figured it out:
$home_slider = new \Concrete\Core\Page\PageList();
$home_slider->filterByAttribute("is_featured",1);
$home_slider->sortByPublicDateDescending();
$pagination = $home_slider->getPagination();
$pagination->setMaxPerPage(4)->setCurrentPage(1);
$results = $pagination->getCurrentPageResults();

But how do I define an offset like in the old get() method? setCurrentPage(2)? Is this the correct way to do it? This makes much less sense than 5.6...
VPenkov replied on at Permalink Best Answer Reply
VPenkov
Ok, this is most likely NOT the way to do it as I ended up having a MASSIVE CPU usage - like 20% from a huge octa-core CPU by serving 5 simple (ish) page lists from a website with <100 pages. With caching turned on.

There's also the memory issue which basically is that 512MB of memory_limit sometimes aren't enough.

Any input would be much appreciated.

Edit: there's something I seem to have missed - setItemsPerPage:
$home_slider = new \Concrete\Core\Page\PageList();
$home_slider->filterByAttribute("is_featured",1);
$home_slider->sortByPublicDateDescending();
$home_slider->setItemsPerPage(4);
$pagination = $home_slider->getPagination();
$pagination->setMaxPerPage(4)->setCurrentPage(1);
$results = $pagination->getCurrentPageResults();

It's likely the answer to my question but I'll wait until someone confirms.