您好,登錄后才能下訂單哦!
小編給大家分享一下Zend Framework框架如何實現(xiàn)類似Google搜索分頁效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
具體如下:
/** * * @param unknown_type $model 表類型 * @param unknown_type $ncontroller 那個控制器提交的controller * @param unknown_type $naction 那個action提交的action */ public function fenyepage2($model,$ncontroller,$naction){ if(!isset($_SESSION)) {session_start();} $pageSize = $_SESSION['pagesize']; $pageNow = $_SESSION['pagenow']; $offset = ($pageNow-1)*$pageSize; $db = $this->getAdapter(); $select = $db->select(); $select->from('student','*'); if(!isset($_SESSION)) {session_start();} if($_SESSION['qsname']!=""){ $sname = $_SESSION['qsname']; $select->where('sname like ?',"%$sname%"); } if($_SESSION['qsaddress']!=""){ $saddress = $_SESSION['qsaddress']; $select->where('saddress like ?',"%$saddress%"); } if($_SESSION['qsdept']!=""){ $sdept = $_SESSION['qsdept']; $select->where('sdept like ?',"%$sdept%"); } $coutNews = $db->fetchAll($select); $pageCount = ceil(count($coutNews)/$pageSize); $select->limit($pageSize,$offset);//第一個參數(shù):總共顯示多少個。第二個參數(shù):從第幾個開始顯示 $res = $db->fetchAll($select); $native = null; $native = "<a href='\\$ncontroller\\$naction?pageNow=1&pagesize=$pageSize'>首頁</a> "; if($pageNow>1){ $nextPage = $pageNow-1; $native.=" <a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一頁</a> "; } if(($pageNow-1)>5){ if($pageNow+4>$pageCount){//如果最后的頁數(shù)和理應(yīng)前面開始的頁數(shù)小于10則 $start = $pageCount-9;//開始的頁數(shù)和結(jié)束的頁數(shù)相差9 }else{ $start=$pageNow-5;//開始位置和結(jié)束位置相差5 } }else{ $start = floor(($pageNow-1)/10)*10+1; } if($pageCount>=$start+10){ $index = $start+10; } else{ $index = $pageCount+1; } for(;$start<$index;$start++){ $native.=" <a href='\\$ncontroller\\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>"; } if($pageNow<$pageCount){ $nextPage = $pageNow+1; $native.=" <a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一頁</a> "; } $native.=" <a href='\\$ncontroller\\$naction?pageNow=$pageCount&pagesize=$pageSize'>末頁</a> "; $native.=" 當(dāng)前{$pageNow}||總共{$pageCount}頁"; $model->arrs = $res; $model->native = $native; }
以上是“Zend Framework框架如何實現(xiàn)類似Google搜索分頁效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。