我正在尝试使用 http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php/中的分页器类,但由于某种原因,我无法在 smarty var 中输出分页链接我的模板。
我试过这个:
function listadverts($where = null, $orderby = null, $limit = null) {
$pages = new Paginator;
$pages->items_total = $this->countadverts($where);
$pages->mid_range = 9;
$pages->paginate();
$row = $this->db->dbh->query('SELECT ad.*, (SELECT img.image FROM '.$this->config->db_prefix.'_images AS img WHERE img.aid = ad.aid LIMIT 1) AS img FROM '.$this->config->db_prefix.'_adverts ad WHERE (ad.approved = 1) '. $where .' ORDER BY '.$orderby.' cr_date DESC '. $pages->limit .'');
$smarty = new Smarty();
$smarty->assign('paginate', $pages->display_pages());
return $row;
}
在我的模板中我有
{$paginate}
功能
$pages->display_pages()
返回$this->return;
其中 $this->returns 包含此 HTML
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$target?page=$i&ipp=$this->items_per_page\">$i</a> ";
{$paginate|@var_dump} 只返回 NULL,但如果我 var_dump($smarty) 我可以看到
["paginate"]=> object(Smarty_Variable)#114 (3) { ["value"]=> string(227) "1 2 3 4 All "
解决方案:
return array(0 => $row, 1 => $pages->display_pages());
$res = $adverts->listadverts();
$app->view()->setData('adverts', $res[0]);
$app->view()->setData('paginate', $res[1]);