/** * 获取最后一次访问的列表页参数 * @param array $params * @return array */ public function getLLUParams(array $params = array()) { $attributes = isset($params['attributes']) ? (array) $params['attributes'] : array(); $order = isset($params['order']) ? trim($params['order']) : ''; $listRows = isset($params['limit']) ? (int) $params['limit'] : 0; $firstRow = isset($params['offset']) ? (int) $params['offset'] : 0; if ($order !== '') { $attributes['order'] = $order; } if ($listRows <= 0) { return $attributes; } if ($listRows !== (int) Cfg::getApp('list_rows', 'paginator')) { $attributes[PageHelper::getListRowsVar()] = $listRows; } $firstRow = max($firstRow, 0); $currPage = floor($firstRow / $listRows) + 1; if ($currPage > 0) { $attributes[PageHelper::getPageVar()] = $currPage; } return $attributes; }
/** * 获取分页处理类 * @return \tfc\util\Paginator */ public function getPaginator() { // 总的记录数 <= 0,表示不需要分页 if (($totalRows = $this->getTotalRows()) <= 0) { return null; } $attributes = isset($this->_tplVars['attributes']) ? (array) $this->_tplVars['attributes'] : array(); $order = isset($this->_tplVars['order']) ? trim($this->_tplVars['order']) : ''; $listRows = isset($this->_tplVars['limit']) ? (int) $this->_tplVars['limit'] : 0; $firstRow = isset($this->_tplVars['offset']) ? (int) $this->_tplVars['offset'] : 0; // 每页展示的行数 <= 0,表示第一页展示所有数据 if ($listRows <= 0) { return null; } if ($order !== '') { $attributes['order'] = $order; } if ($listRows !== (int) Cfg::getApp('list_rows', 'paginator')) { $attributes[PageHelper::getListRowsVar()] = $listRows; } $firstRow = max($firstRow, 0); $currPage = floor($firstRow / $listRows) + 1; $url = $this->getUrlManager()->getUrl(Mvc::$action, Mvc::$controller, Mvc::$module, $attributes); $paginator = new Paginator($totalRows, $url, PageHelper::getPageVar()); $paginator->setListPages(PageHelper::getListPages()); $paginator->setListRows($listRows); $paginator->setCurrPage($currPage); return $paginator; }