8.4.2: How to paginate an array?

Permalink
How can I paginate an array?

The only thing I could find and think of is this:
use Concrete\Core\Legacy\ItemList;
$items = ['file1','file2','file3'];
$files = new ItemList();
$files->setItemsPerPage(10);
$files->setItems($items);
$factory = new PaginationFactory($this->app->make(Request::class));
$paginator = $factory->createPaginationObject($files);
$pagination = $paginator->renderDefaultView();    // <- ERROR!
$this->set('files', $paginator->getCurrentPageResults());
$this->set('pagination', $pagination);
$this->set('paginator', $paginator);

and
foreach ($files as $file) {
    echo $file;
}

But I've got an error:
Call to undefined method Concrete\Core\Legacy\Pagination::renderDefaultView()

Looks like the legacy pagination is not compatible with the new version. Any idea how to paginate an array of strings in v8.4*?

Will appreciate any help. Thank you.

linuxoid
 
mnakalay replied on at Permalink Reply
mnakalay
Maybe try this
$pagination = $files->displayPagingV2(false, true);
linuxoid replied on at Permalink Best Answer Reply
linuxoid
I got it! Thank you very much.

$path = DIR_FILES_UPLOADED_STANDARD . '/' . $this->file_path;
$contents = $fh->getDirectoryContents($path);
$files = new ItemList();
$files->setItemsPerPage(10);
$files->setItems($contents);
$factory = new PaginationFactory($this->app->make(Request::class));
$paginator = $factory->createPaginationObject($files);
$pagination = $files->displayPagingV2(false, true);
$this->set('files', $files->getPage());
$this->set('pagination', $pagination);
$this->set('paginator', $paginator);