国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > PHP > 正文

Zend Framework分頁(yè)類(lèi)用法詳解

2024-05-04 23:44:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這篇文章主要介紹了Zend Framework分頁(yè)類(lèi)用法,結(jié)合實(shí)例形式詳細(xì)分析了Zend Framework分頁(yè)類(lèi)的實(shí)現(xiàn)代碼,相關(guān)功能與使用技巧,需要的朋友可以參考下
 

本文實(shí)例講述了Zend Framework分頁(yè)類(lèi)用法。分享給大家供大家參考,具體如下:

1、分頁(yè)類(lèi)Pagination.php,最好是把這個(gè)類(lèi)放在Zend目錄下

class XY_Pagination{  private $_navigationItemCount = 10; //導(dǎo)航欄顯示導(dǎo)航總頁(yè)數(shù)  private $_pageSize = null; //每頁(yè)項(xiàng)目數(shù)  private $_align = "right"; //導(dǎo)航欄顯示位置  private $_itemCount = null; //總項(xiàng)目數(shù)  private $_pageCount = null; //總頁(yè)數(shù)  private $_currentPage = null; //當(dāng)前頁(yè)  private $_front = null; //前端控制器  private $_PageParaName = "page"; //頁(yè)面參數(shù)名稱(chēng)  private $_firstPageString = "|<<"; //導(dǎo)航欄中第一頁(yè)顯示的字符  private $_nextPageString = ">>"; //導(dǎo)航欄中前一頁(yè)顯示的字符  private $_previousPageString = "<<"; //導(dǎo)航欄中后一頁(yè)顯示的字符  private $_lastPageString = ">>|"; //導(dǎo)航欄中最后一頁(yè)顯示的字符  private $_splitString = " | ";         //頁(yè)數(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); //總頁(yè)數(shù)    $page = $this->_front->getRequest()->getParam($this->_PageParaName);    if(empty($page) || (!is_numeric($page))) //為空或不是數(shù)字,設(shè)置當(dāng)前頁(yè)為1    {      $this->_currentPage = 1;    }    else    {      if($page < 1)        $page = 1;      if($page > $this->_pageCount)        $page = $this->_pageCount;      $this->_currentPage = $page;    }  }  /**   * 返回當(dāng)前頁(yè)   * @param int 當(dāng)前頁(yè)   */  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)前頁(yè)處于第幾欄分頁(yè)    $pageCoteCount = ceil($this->_pageCount / ($this->_navigationItemCount - 1)); //總分頁(yè)欄    $pageStart = $pageCote * ($this->_navigationItemCount -1) + 1; //分頁(yè)欄中起始頁(yè)    $pageEnd = $pageStart + $this->_navigationItemCount - 1; //分頁(yè)欄中終止頁(yè)    if($this->_pageCount < $pageEnd)    {      $pageEnd = $this->_pageCount;    }        $navigation .= "總共:{$this->_itemCount}條 {$this->_pageCount}頁(yè)/n";    if($pageCote > 0) //首頁(yè)導(dǎo)航    {      $navigation .= '$this->_firstPageString ";    }    if($this->_currentPage != 1) //上一頁(yè)導(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) //下一頁(yè)導(dǎo)航    {      $navigation .= ' $this->_nextPageString ";    }    if($pageCote < $pageCoteCount-1) //未頁(yè)導(dǎo)航    {      $navigation .= '$this->_lastPageString ";    }    //添加直接導(dǎo)航框    //$navigation .= '';    //2008年8月27號(hào)補(bǔ)充輸入非正確頁(yè)碼后出現(xiàn)的錯(cuò)誤——begin    $navigation .= ' ';    //2008年8月27號(hào)補(bǔ)充輸入非正確頁(yè)碼后出現(xiàn)的錯(cuò)誤——end    $navigation .= " ";    return $navigation;  }  /**   * 取得導(dǎo)航欄顯示導(dǎo)航總頁(yè)數(shù)   *   * @return int 導(dǎo)航欄顯示導(dǎo)航總頁(yè)數(shù)   */  public function getNavigationItemCount()  {    return $this->_navigationItemCount;  }  /**   * 設(shè)置導(dǎo)航欄顯示導(dǎo)航總頁(yè)數(shù)   *   * @param int $navigationCount:導(dǎo)航欄顯示導(dǎo)航總頁(yè)數(shù)   */  public function setNavigationItemCoun($navigationCount)  {    if(is_numeric($navigationCount))    {      $this->_navigationItemCount = $navigationCount;    }  }  /**   * 設(shè)置首頁(yè)顯示字符   * @param string $firstPageString 首頁(yè)顯示字符   */  public function setFirstPageString($firstPageString)  {    $this->_firstPageString = $firstPageString;  }  /**   * 設(shè)置上一頁(yè)導(dǎo)航顯示字符   * @param string $previousPageString:上一頁(yè)顯示字符   */  public function setPreviousPageString($previousPageString)  {    $this->_previousPageString = $previousPageString;  }  /**   * 設(shè)置下一頁(yè)導(dǎo)航顯示字符   * @param string $nextPageString:下一頁(yè)顯示字符   */  public function setNextPageString($nextPageString)  {    $this->_nextPageString = $nextPageString;  }  /**   * 設(shè)置未頁(yè)導(dǎo)航顯示字符   * @param string $nextPageString:未頁(yè)顯示字符   */  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è)置頁(yè)面參數(shù)名稱(chēng)   * @param string $pageParamName:頁(yè)面參數(shù)名稱(chēng)   */  public function setPageParamName($pageParamName)  {    $this->_PageParaName = $pageParamName;  }  /**   * 獲取頁(yè)面參數(shù)名稱(chēng)   * @return string 頁(yè)面參數(shù)名稱(chēng)   */  public function getPageParamName()  {    return $this->_PageParaName;  }  /**   * 生成導(dǎo)航鏈接地址   * @param int $targetPage:導(dǎo)航頁(yè)   * @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)頁(yè)      $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(); //查詢(xún)記錄總數(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)用分頁(yè)更簡(jiǎn)單了。

pagebar?>

或者在smarty模板情況下

<{$pagebar}>



發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 迁西县| 白山市| 安远县| 沧州市| 平邑县| 南乐县| 开阳县| 八宿县| 宁阳县| 凤山县| 塘沽区| 宽甸| 花莲市| 长寿区| 柘荣县| 明光市| 福建省| 内江市| 沙田区| 鸡泽县| 曲阜市| 鄂伦春自治旗| 即墨市| 湖南省| 康乐县| 婺源县| 荔浦县| 崇州市| 霍城县| 勃利县| 法库县| 玉树县| 天津市| 长岭县| 浙江省| 金堂县| 文山县| 滦南县| 玉门市| 同心县| 姜堰市|