Last updated January 16, 2013. Created by alarcombe on September 6, 2012.
Edited by bfr. Log in to edit this page.
If you write a custom backend for Views 3 (eg you have an external data source that you wish to expose through a view) you'll need to ensure that you carry out the following steps in order that views' full- and mini-pagers work.
1. Add the following to the build() method of your query object:
/*
this creates a new pager object within the view
*/
$view->init_pager();
/*
this takes the settings from the pager object (eg items per page - this could be innate or set via an exposed
filter and makes them available to the view
*/
$this->pager->query();2. add the following to the execute() method of your query object:
/*
set the total number of items that exist in this query
eg select count(*) from foo;
*/
$this->pager->total_items = $total_items_in_view;
/*
this does the final calculations to work out the current offset and
number of pages based on total items, exposed views etc
*/
$this->update_page_info();
/*
$this->offset and $this->limit now contain the 0th indexed first
row to display and the number of rows to return so we can eg do
select foo from bar limit {$this->offset} {$this->limit};
*/