程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> ZendFramework中的分頁類實現

ZendFramework中的分頁類實現

編輯:PHP綜合

參考自:http://www.phpfans.net/ask/question2/7822122562.html

其實上文寫得比較清楚了,我這也只是把上面的方法推廣一下而已。

主要是分頁類的實現。

如上圖文件結構所示,在library目錄下新建Custom模塊。各個文件的代碼依次是:

Mysql.php

1.<?php
2.require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
3.4.class Custom_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql
5.{
6. public function fatchPage($sql, $pagesize=20, $currentpage=1)
7. {
8. $currentpage = is_numeric($currentpage) ? $currentpage : 1 ;
9. $result = array();
10. $result_array = $this->query($sql);
11. $result['count'] = count($result_array->fetchAll());
12. $result['pagecount'] = $result['count']/$pagesize>1 ? ceil($result['count']/$pagesize) : 1;
13. $offset = ($currentpage-1)*$pagesize;
14. $result['currentpage'] = $currentpage;
15. $result['firstpage'] = 1;
16. $result['lastpage'] = $result['pagecount'];
17. $sql .= ' '.$this->select()->limit($pagesize, $offset)->__toString();
18. $result['table'] = $this->query($sql)->fetchAll();
19. return $result;
20. }
21.}
22.?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved