码迷,mamicode.com
首页 > 其他好文 > 详细

yii2.0分页

时间:2014-09-10 12:14:10      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   2014   div   cti   

本实例是对商品列表进行分页

1.Controller中,商品列表的方法actionList

  引用分页类

        bubuko.com,布布扣

        actionList中:

        $goods_info=Goods::find()->joinWith(‘brand‘,‘category‘)->orderBy(‘goods.goods_id desc‘);
        $brand_model=new Brand();
        $brand_info=$brand_model::find()->all();
        $pages = new Pagination([‘totalCount‘=>$goods_info->count(),‘pageSize‘=>5]);
        $goods_info1=$goods_info->offset($pages->offset)->limit($pages->limit)->all();
        return $this->render(‘list‘,[‘goods_info‘=>$goods_info1,‘brand_info‘=>$brand_info,‘brand_model‘=>$brand_model,‘pages‘ => $pages]);

2.视图页面list.php中

use yii\widgets\LinkPager;

 

 

 

bubuko.com,布布扣

 

<div class="text-right">
      <?= LinkPager::widget([‘pagination‘ => $pages]) ?>
</div> 

bubuko.com,布布扣

 

至此,yii2默认的分页已经完成,显示效果如图:

bubuko.com,布布扣

 

yii2.0分页

标签:des   style   blog   http   color   io   2014   div   cti   

原文地址:http://www.cnblogs.com/xlz307/p/3963993.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!