Phalcon分页,虽然官网有例子,但关于builder的写法,还是让我头疼了很久,
controller部分
$builder = $this->modelsManager->createBuilder()
->columns('books.id,books.book_name,books.author,books.press,books.status,books.own_id,u.email')
->from('books')
->leftjoin('users', 'books.own_id = u.id','u') //一旦用了alias ,则都需要用别名 ,leftjoin是自己瞎蒙的,API里没看到这个函数
->orderBy('books.status');
$paginator = new PhalconPaginatorAdapterQueryBuilder(array(
"builder" => $builder,
"limit"=> 2,
"page" => $currentPage,
));
$page = $paginator->getPaginate();
//获取里面的值,测试用,看是否拿到join的数据
foreach($page->items as $items){ //皆可得到
echo $items->author;
echo $items->email;
exit;
}
view下面--推荐用bootstrap
<?php if($page->total_pages > 1):?>
<div class="page_margin">
<ul class="pagination ">
<li class="<?php echo $page->current <= 1?'disabled':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$page->before));?>">«</a></li>
<?php for($i = 1;$i <= $page->total_pages;$i++):?>
<li class="<?php echo $page->current == $i?'active':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$i));?>"><?php echo $i; ?></a></li>
<?php endfor; ?>
<li class="<?php echo $page->current >= $page->total_pages?'disabled':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$page->next));?>">»</a></li>
</ul>
</div>
<?php endif;?>
相关链接:
http://www.myleftstudio.com/reference/pagination.html //Phalcon官网讲解