Adding pagination to looped items in own plugin

Hi.

I've developed a search plugin that combines DC:titles and some other fields from special item types, has an autocomplete dropdown etc. It works well.

This plugin (Quickie) has an items controller that extends Omeka_Controller_AbstractActionController. In my items controller, there's a browseAction() that does the backend searching and returns the items to the viewer

$this->view->items = $items;

In the viewer, I have a regular loop that goes through the items and presents them in accordance with my theme.

<?php foreach (loop('items') as $item):?>
blah blah
<?php endforeach;?>

My plugin is reachable under /blahblah.com/quickie/...

Now, the only trouble is that sometimes I get many results and I would like them to be shown paginated. But echoing pagination_links etc. doesn't do anything useful. I always get all the items shown.

How and where can I make sure that the looped items displayed by my plugin actually follow the system's pagination settings (no of items per page) and show pagination if the number of items returned is larger than the number of items per page?

All best,
Toma

I'm guessing that your browseAction is digging up all the records, and passing them all in to the view, and it completely overrides browseAction from Omeka_Controller_AbstractActionController.

If you dig around in Omeka_Controller_AbstractActionController's browseAction, you'll see the bits where the pagination happens, starting around line 124.

You'll likely need to copy and modify that code in your own browseAction, since it sounds like you're getting the records differently for this purpose. But, generally, the pattern there should be adaptable to what you need.

In particular, this from the abstract controller will likely need modifying:

$records = $this->_helper->db->findBy($params, $recordsPerPage, $currentPage);

When you dig up the records as the result of the search, you'll just need something in how you query for records to deal with $recordsPerPage and $currentPage. That might be somewhere in a Model, depending on how your plugin works.

The rest of the surrounding code from the abstract controller should then just be cut-n-paste.