Re: Pager_Wrapper is wonderful!
| From: | garak at studenti dot it | Date: | Tue, 23 Nov 2004 12:14:01 +0000 |
| Subject: | Re: Pager_Wrapper is wonderful! | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15767@lists.php.net to get a copy of this message | ||
> But, is possible to use with Data_Object?
I wrote this one:
function PagerWrapperDBDO(&$db, $pagerOpt = array(), $disabled = false)
{
if (!array_key_exists('totalItems', $pagerOpt)) {
// be smart and try to guess the total number of records
$totalItems = $db->count();
$pagerOpt['totalItems'] = $totalItems;
}
require_once 'Pager/Pager.php';
$pager = Pager::factory($pagerOpt);
$page = array();
$page['links'] = $pager->links;
$page['page_numbers'] = array(
'current' => $pager->getCurrentPageID(),
'total' => $pager->numPages()
);
list($page['from'], $page['to']) = $pager->getOffsetByPageId();
$page['limit'] = $page['to'] - $page['from'] + 1;
if (!$disabled) {
$db->limit($page['from'] - 1, $pagerOpt['perPage']);
}
$db->find();
while ($db->fetch()) {
$page['data'][] = $db->toArray();
}
return $page;
}
--
Massimiliano Arione
:: http://www.garak.it/ ::
** NO WORD http://www.gnu.org/philosophy/no-word-attachments.html
**
** NO HTML http://www.efn.no/html-bad.html **