Welcome 微信登录

首页 / 网页编程 / PHP / ZendFramework中的分页类实现

ZendFramework中的分页类实现2010-10-05月影传说参考自: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.?>