First use the reference paging Class 1,
1 use yii\data\pagination;
2. Controller
1 //Paging Jump2 Public functionActionpagego () {3 $model= Knowledge::find ();4 //Native SQL statements use paging5 $sql= "Select K.id,k.title,k.copyfrom,k.username,k.updatetime from Bl_knowledge K left joins BL_KR KR on K.id=kr.knowledgeid LE FT 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=Newpagination ([8' Defaultpagesize ' =>2,9' TotalCount ' =Count($list),Ten ]); One $counts=Count($list); A $all _pages=Ceil($counts/10); - $display _pagego= 1; - $result= Yii::$app->db->createcommand ($sql. "Limit".$pagination->limit. "Offset".$pagination->offset. "") -Queryall (); the - return $this->renderpartial (' Index ',[ -' Model ' =$model, -' Result ' =$result, +' Counts ' =$counts, -' Pagination ' =$pagination, +' All_pages ' =$all _pages, A' Display_pagego ' =$display _pagego, at ]); -}
4, the page calls the current controller, the method, be sure to get to the number of pages to jump
1 //Paging Jump2$ ("#tiaozhuango"). Click (function(){3 varTiaozhuan = $ (". Tiaozhuan").Val ();4 if(Tiaozhuan) {5Location.href= "/index.php?r=overseasknow/pagego&page=" +Tiaozhuan;6}Else{7location.href= "/index.php?r=overseasknow/index";8 }9});
5, note: The parameters passed must be "page" because, Yii2 in the paging class, the number of delivery page is to jump page reference: Yii\data\pagination file
Yii2 do input jump to paging