Yii用原生分页
視圖封裝
<?php use \app\common\services\UrlService; ?> <div class="row"><div class="col-lg-12"><span class="pagination_count" style="line-height: 40px;">共<?=$pages['total_count'];?>條記錄 | 每頁<?=$pages['page_size'];?>條</span><ul class="pagination pagination-lg pull-right" style="margin: 0 0 ;"><?php for( $_page = 1;$_page <= $pages['total_page'];$_page++ ):?><?php if( $_page == $pages['p'] ):?><li class="active"><a href="<?=UrlService::buildNullUrl();?>"><?=$_page;?></a></li><?php else:?><li><a href="<?=UrlService::buildWebUrl( $url,[ 'p' => $_page ] );?>"><?=$_page;?></a></li><?php endif;?><?php endfor;?></ul></div> </div>視圖使用
<?php echo Yii::$app->getView()->renderFile("@app/modules/web/views/common/page.php",['pages' => $pages,'url' => '/member/index']);?>控制器
public function actionIndex(){$mix_kw = trim( $this->get("mix_kw","") );$status = intval( $this->get("status",ConstantMapService::$status_default) );$p = intval( $this->get("p",1) );$p = ( $p > 0 ) ? $p : 1;$query = Member::find();if( $mix_kw ){$where_nickname = [ 'LIKE','nickname','%'.strtr($mix_kw,['%'=>'\%', '_'=>'\_', '\\'=>'\\\\']).'%', false ];$where_mobile = [ 'LIKE','mobile','%'.strtr($mix_kw,['%'=>'\%', '_'=>'\_', '\\'=>'\\\\']).'%', false ];$query->andWhere([ 'OR',$where_nickname,$where_mobile ]);}if ($status > ConstantMapService::$status_default ){$query->andWhere(['status' => $status ]);}$page_size = 1;$total_res_count = $query->count();$total_page = ceil($total_res_count / $page_size );$offset = ($p - 1)*$page_size;$list = $query -> orderBy(['id' => SORT_DESC ])->offset($offset)->limit($page_size)->all();return $this->render('index',['list' => $list,'pages' => ['total_count' => $total_res_count,'page_size' => $page_size,'total_page' => $total_page,'p' => $p],'status_mapping' => ConstantMapService::$status_mapping,'search_conditions' => ['mix_km' => $mix_kw,'p' => $p,'status' => $status,]]);}?
總結
- 上一篇: PHP的exec
- 下一篇: 广厂上面画上爱心图片应该起名叫什么厂呢?