2007-8-15 01:46
wohugb
想问一下有没有人做过分页?
如题,我找了哥分页类Riskle_Db_Table_Paginate ,但却不会使用,按照他的提示
And here is how it is used in the controller:
public function indexAction() {
$urls = new Riskle_Db_Table_Paginate(new Urls, $this->_getParam('page'));
$this->view->urlsList = $urls->fetchAll(null, 'datetime DESC');
$this->view->paginationInfos = $urls->getPaginationInfos();
}
The view helper takes paginationInfos as an argument:
echo $this->paginate($this->paginationInfos);
,但不知道这个urls是什么东西?
2007-11-16 17:23
liyong98847
public function indexAction()
{
$this->view->title = "Co. Albums";
$Album = new Album();
// Define limit
$count = 5;
// Get total rows
$totalRows = $Album->fetchAll()->count();
// Get total pages
$totalPages = ceil($totalRows / $count);
// Define current page
$page = (int)$this->_getParam("page");
if ($page < 1 || $page > $totalPages) $page = 1;
// Define offset
$offset = ($page - 1) * $count;
$this->view->totalRows = $totalRows;
$this->view->totalPages = $totalPages;
$this->view->offset = $offset;
$this->view->count = $count;
$this->view->page = $page;
$this->view->albums = $Album->fetchAll(null, null, $count, $offset)->toArray();
}