Zend Framework分頁類用法詳解,zendframework_PHP教程
Jul 12, 2016 am 08:56 AMZend Framework分頁類用法詳解,zendframework
本文實(shí)例講述了Zend Framework分頁類用法。分享給大家供大家參考,具體如下:
1、分頁類Pagination.php,最好是把這個類放在Zend目錄下
class XY_Pagination { private $_navigationItemCount = 10; //導(dǎo)航欄顯示導(dǎo)航總頁數(shù) private $_pageSize = null; //每頁項(xiàng)目數(shù) private $_align = "right"; //導(dǎo)航欄顯示位置 private $_itemCount = null; //總項(xiàng)目數(shù) private $_pageCount = null; //總頁數(shù) private $_currentPage = null; //當(dāng)前頁 private $_front = null; //前端控制器 private $_PageParaName = "page"; //頁面參數(shù)名稱 private $_firstPageString = "|<<"; //導(dǎo)航欄中第一頁顯示的字符 private $_nextPageString = ">>"; //導(dǎo)航欄中前一頁顯示的字符 private $_previousPageString = "<<"; //導(dǎo)航欄中后一頁顯示的字符 private $_lastPageString = ">>|"; //導(dǎo)航欄中最后一頁顯示的字符 private $_splitString = " | "; //頁數(shù)字間的間隔符 / public function __construct($itemCount, $pageSize) { if(!is_numeric($itemCount) || (!is_numeric($pageSize))) throw new Exception("Pagination Error:not Number"); $this->_itemCount = $itemCount; $this->_pageSize = $pageSize; $this->_front = Zend_Controller_Front::getInstance(); $this->_pageCount = ceil($itemCount/$pageSize); //總頁數(shù) $page = $this->_front->getRequest()->getParam($this->_PageParaName); if(empty($page) || (!is_numeric($page))) //為空或不是數(shù)字,設(shè)置當(dāng)前頁為1 { $this->_currentPage = 1; } else { if($page < 1) $page = 1; if($page > $this->_pageCount) $page = $this->_pageCount; $this->_currentPage = $page; } } /** * 返回當(dāng)前頁 * @param int 當(dāng)前頁 */ public function getCurrentPage() { return $this->_currentPage; } /** * 返回導(dǎo)航欄目 * @return string 導(dǎo)航html class="PageNavigation" */ public function getNavigation() { $navigation = ''; $pageCote = ceil($this->_currentPage / ($this->_navigationItemCount - 1)) - 1; //當(dāng)前頁處于第幾欄分頁 $pageCoteCount = ceil($this->_pageCount / ($this->_navigationItemCount - 1)); //總分頁欄 $pageStart = $pageCote * ($this->_navigationItemCount -1) + 1; //分頁欄中起始頁 $pageEnd = $pageStart + $this->_navigationItemCount - 1; //分頁欄中終止頁 if($this->_pageCount < $pageEnd) { $pageEnd = $this->_pageCount; } $navigation .= "總共:{$this->_itemCount}條 {$this->_pageCount}頁\n"; if($pageCote > 0) //首頁導(dǎo)航 { $navigation .= '$this->_firstPageString "; } if($this->_currentPage != 1) //上一頁導(dǎo)航 { $navigation .= '$this->_previousPageString "; } while ($pageStart <= $pageEnd) //構(gòu)造數(shù)字導(dǎo)航區(qū) { if($pageStart == $this->_currentPage) { $navigation .= "$pageStart".$this->_splitString; } else { $navigation .= '$pageStart".$this->_splitString; } $pageStart++; } if($this->_currentPage != $this->_pageCount) //下一頁導(dǎo)航 { $navigation .= ' $this->_nextPageString "; } if($pageCote < $pageCoteCount-1) //未頁導(dǎo)航 { $navigation .= '$this->_lastPageString "; } //添加直接導(dǎo)航框 //$navigation .= ''; //2008年8月27號補(bǔ)充輸入非正確頁碼后出現(xiàn)的錯誤——begin $navigation .= ' '; //2008年8月27號補(bǔ)充輸入非正確頁碼后出現(xiàn)的錯誤——end $navigation .= " "; return $navigation; } /** * 取得導(dǎo)航欄顯示導(dǎo)航總頁數(shù) * * @return int 導(dǎo)航欄顯示導(dǎo)航總頁數(shù) */ public function getNavigationItemCount() { return $this->_navigationItemCount; } /** * 設(shè)置導(dǎo)航欄顯示導(dǎo)航總頁數(shù) * * @param int $navigationCount:導(dǎo)航欄顯示導(dǎo)航總頁數(shù) */ public function setNavigationItemCoun($navigationCount) { if(is_numeric($navigationCount)) { $this->_navigationItemCount = $navigationCount; } } /** * 設(shè)置首頁顯示字符 * @param string $firstPageString 首頁顯示字符 */ public function setFirstPageString($firstPageString) { $this->_firstPageString = $firstPageString; } /** * 設(shè)置上一頁導(dǎo)航顯示字符 * @param string $previousPageString:上一頁顯示字符 */ public function setPreviousPageString($previousPageString) { $this->_previousPageString = $previousPageString; } /** * 設(shè)置下一頁導(dǎo)航顯示字符 * @param string $nextPageString:下一頁顯示字符 */ public function setNextPageString($nextPageString) { $this->_nextPageString = $nextPageString; } /** * 設(shè)置未頁導(dǎo)航顯示字符 * @param string $nextPageString:未頁顯示字符 */ public function setLastPageString($lastPageString) { $this->_lastPageString = $lastPageString; } /** * 設(shè)置導(dǎo)航字符顯示位置 * @param string $align:導(dǎo)航位置 */ public function setAlign($align) { $align = strtolower($align); if($align == "center") { $this->_align = "center"; }elseif($align == "right") { $this->_align = "right"; }else { $this->_align = "left"; } } /** * 設(shè)置頁面參數(shù)名稱 * @param string $pageParamName:頁面參數(shù)名稱 */ public function setPageParamName($pageParamName) { $this->_PageParaName = $pageParamName; } /** * 獲取頁面參數(shù)名稱 * @return string 頁面參數(shù)名稱 */ public function getPageParamName() { return $this->_PageParaName; } /** * 生成導(dǎo)航鏈接地址 * @param int $targetPage:導(dǎo)航頁 * @return string 鏈接目標(biāo)地址 */ private function createHref($targetPage = null) { $params = $this->_front->getRequest()->getParams(); $module = $params["module"]; $controller = $params["controller"]; $action = $params["action"]; $targetUrl = $this->_front->getBaseUrl()."/$module/$controller/$action"; foreach ($params as $key => $value) { if($key != "controller" && $key != "module" && $key != "action" && $key != $this->_PageParaName) { $targetUrl .= "/$key/$value"; } } if(isset($targetPage)) //指定目標(biāo)頁 $targetUrl .= "/$this->_PageParaName/$targetPage"; else $targetUrl .= "/$this->_PageParaName/"; return $targetUrl; } } ?>
2、在indexController.php中的indexController Function里面調(diào)用:
require_once 'Zend/Pagination.php'; $Users = new Users(); //$rows = $Users->getAdapter()->fetchOne("select count(*) from users where `role`!='admin'"); //recorde count $rows = $Users->fetchAll("`role`!='admin'")->count(); //查詢記錄總數(shù) $rowsPerPage = 5; //perPage recordes $curPage = 1; if($this->_request->getParam('page')) { $curPage = $this->_request->getParam('page'); } //search data and display $this->view->users = $Users->fetchAll("`role`!='admin'",'id desc',$rowsPerPage,($curPage-1)*$rowsPerPage)->toArray(); $Pager = new XY_Pagination($rows,$rowsPerPage); $this->view->pagebar = $Pager->getNavigation();
3、在view中調(diào)用分頁更簡單了。
pagebar?>
或者在smarty模板情況下
更多關(guān)于zend相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《Yii框架入門及常用技巧總結(jié)》、《ThinkPHP入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Zend Framework框架的PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- Zend Framework框架教程之Zend_Db_Table_Rowset用法實(shí)例分析
- Zend Framework教程之Zend_Db_Table_Row用法實(shí)例分析
- Zend Framework教程之Zend_Db_Table用法詳解
- Zend Framework教程之Zend_Form組件實(shí)現(xiàn)表單提交并顯示錯誤提示的方法
- Zend Framework開發(fā)入門經(jīng)典教程
- Zend Framework框架Smarty擴(kuò)展實(shí)現(xiàn)方法
- Zend Framework框架路由機(jī)制代碼分析
- Zend Framework實(shí)現(xiàn)具有基本功能的留言本(附demo源碼下載)
- Zend Framework實(shí)現(xiàn)將session存儲在memcache中的方法
- Zend Framework實(shí)現(xiàn)多文件上傳功能實(shí)例
- Zend Framework入門之環(huán)境配置及第一個Hello World示例(附demo源碼下載)
- Zend Framework教程之連接數(shù)據(jù)庫并執(zhí)行增刪查的方法(附demo源碼下載)
- Zend Framework教程之Zend_Db_Table表關(guān)聯(lián)實(shí)例詳解

熱AI工具

Undress AI Tool
免費(fèi)脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

每當(dāng)您的Windows11或Windows10PC出現(xiàn)升級或更新問題時,您通常會看到一個錯誤代碼,指示故障背後的實(shí)際原因。但是,有時,升級或更新失敗可能不會顯示錯誤代碼,這時就會混淆。有了方便的錯誤代碼,您可以確切地知道問題出在哪裡,因此您可以嘗試修復(fù)。但是由於沒有出現(xiàn)錯誤代碼,因此識別問題並解決它變得極具挑戰(zhàn)性。這會佔(zhàn)用您大量時間來簡單地找出錯誤背後的原因。在這種情況下,您可以嘗試使用Microsoft提供的名為SetupDiag的專用工具,該工具可協(xié)助您輕鬆識別錯誤背後的真

.NETFramework4是開發(fā)人員和最終使用者在Windows上執(zhí)行最新版本的應(yīng)用程式所必需的。但是,在下載安裝.NETFramework4時,許多用戶抱怨安裝程式在中途停止,顯示以下錯誤訊息-「?.NETFramework4hasnotbeeninstalledbecauseDownloadfailedwitherrorcode0x800c0006?」。在您的裝置上安裝.NETFramework4時,如果您也在體驗(yàn)它,那麼您就來對了地方
![SCNotification 已停止運(yùn)作 [修復(fù)它的 5 個步驟]](https://img.php.cn/upload/article/000/887/227/168433050522031.png?x-oss-process=image/resize,m_fill,h_207,w_330)
身為Windows用戶,您很可能會在每次啟動電腦時遇到SCNotification已停止工作錯誤。 SCNotification.exe是一個微軟系統(tǒng)通知文件,由於權(quán)限錯誤和點(diǎn)網(wǎng)故障等原因,每次啟動PC時都會崩潰。此錯誤也以其問題事件名稱而聞名。因此,您可能不會將其視為SCNotification已停止工作,而是將其視為錯誤clr20r3。在本文中,我們將探討您需要採取的所有步驟來修復(fù)SCNotification已停止運(yùn)作,以免它再次困擾您。什麼是SCNotification.e

PHP實(shí)作框架:ZendFramework入門教學(xué)ZendFramework是PHP開發(fā)的開源網(wǎng)站框架,目前由ZendTechnologies維護(hù),ZendFramework採用了MVC設(shè)計(jì)模式,提供了一系列可重複使用的程式碼庫,服務(wù)於實(shí)作Web2.0應(yīng)用程式和Web服務(wù)。 ZendFramework深受PHP開發(fā)者的歡迎與推崇,擁有廣泛

已安裝Microsoft.NET版本4.5.2、4.6或4.6.1的MicrosoftWindows用戶如果希望Microsoft將來透過產(chǎn)品更新支援該框架,則必須安裝較新版本的Microsoft框架。據(jù)微軟稱,這三個框架都將在2022年4月26日停止支援。支援日期結(jié)束後,產(chǎn)品將不會收到「安全修復(fù)或技術(shù)支援」。大多數(shù)家庭設(shè)備透過Windows更新保持最新。這些設(shè)備已經(jīng)安裝了較新版本的框架,例如.NETFramework4.8。未自動更新的設(shè)備可能

如何在Zend框架中使用ACL(AccessControlList)進(jìn)行權(quán)限控制導(dǎo)言:在一個Web應(yīng)用程式中,權(quán)限控制是至關(guān)重要的功能。它可以確保使用者只能存取其有權(quán)存取的頁面和功能,並防止未經(jīng)授權(quán)的存取。 Zend框架提供了一種方便的方法來實(shí)現(xiàn)權(quán)限控制,即使用ACL(AccessControlList)元件。本文將介紹如何在Zend框架中使用ACL

自從我們談?wù)撚绊懓惭bKB5012643forWindows11的用戶的新安全模式錯誤以來已經(jīng)過去了一周。這個討厭的問題並沒有出現(xiàn)在微軟在發(fā)布當(dāng)天發(fā)布的已知問題清單中,因此讓所有人都感到驚訝。好吧,就在您認(rèn)為情況不會變得更糟的時候,微軟為安裝此累積更新的用戶投下了另一顆炸彈。 Windows11Build22000.652導(dǎo)致更多問題因此,這家科技公司警告Windows11用戶,他們在啟動和使用某些.NETFramework3.5應(yīng)用程式時可能會遇到問題。聽起來很熟悉?不過請不要驚

什麼是0xc0000135錯誤,我為什麼會得到它?根據(jù)Microsoft官方文檔,0xc0000135錯誤代碼與.NetFramework問題有關(guān)。似乎許多需要.NetFramework3.5才能工作的應(yīng)用程式無法與最新的Windows11更新一起使用。這就是導(dǎo)致0xc0000135錯誤代碼的原因,您可以透過在PC上啟用.NetFramework3.5來解決此問題。大多數(shù)現(xiàn)代應(yīng)用程式都依賴.NetFramework.dll檔案在後臺按預(yù)期運(yùn)行。但是
