标签:
1 use yii\data\Pagination;
1 //分页跳转 2 public function actionPagego(){ 3 $model = Knowledge::find(); 4 //原生sql语句使用分页 5 $sql = "SELECT k.id,k.title,k.copyfrom,k.username,k.updatetime FROM bl_knowledge k LEFT JOIN bl_kr kr ON k.id=kr.knowledgeid LEFT JOIN bl_res r ON kr.resourcesid=r.id WHERE k.status=1 GROUP BY k.id ORDER BY k.listorder desc, k.id ASC"; 6 $list = Yii::$app->db->createCommand($sql)->queryAll(); 7 $pagination = new Pagination([ 8 ‘defaultPageSize‘=>2, 9 ‘totalCount‘=>count($list), 10 ]); 11 $counts = count($list); 12 $all_pages = ceil($counts/10); 13 $display_pagego = 1; 14 $result = Yii::$app->db->createCommand($sql." limit ".$pagination->limit." offset ".$pagination->offset."")->queryAll(); 15 16 return $this->renderPartial(‘index‘,[ 17 ‘model‘ => $model, 18 ‘result‘ => $result, 19 ‘counts‘ => $counts, 20 ‘pagination‘ => $pagination, 21 ‘all_pages‘ => $all_pages, 22 ‘display_pagego‘=> $display_pagego, 23 ]); 24 }
1 //分页跳转 2 $("#tiaozhuango").click(function(){ 3 var tiaozhuan = $(".tiaozhuan").val(); 4 if(tiaozhuan){ 5 location.href="/index.php?r=overseasknow/pagego&page="+tiaozhuan; 6 }else{ 7 location.href="/index.php?r=overseasknow/index"; 8 } 9 });
标签:
原文地址:http://www.cnblogs.com/wamp/p/5365125.html