http://www.schoolcms.cn/ 发布
完善的page分页模块,和百度一模一样
class PagingModel
{
private $m_PagingDataArray; //接收页面提交的post或者get的一维数组条件
private $m_Configuration; //配置项数据
private $m_Fraction; //每个页面显示的条数
private $m_Total; //数据的总条数
private $m_Page; //页面传递过来的页码值
private $m_Starting; //查询数据的起始值
private $m_TotalFraction; //计算出来的总页数
private $m_Url; //分页使用的url地址
private $m_PageCoent; //是否开启页面数字分页按钮
/*
构造方法
*/
public function __construct($PagingDataArray = array(), $Configuration = array())
{
/* 初始化属性数据 */
$this->m_PagingDataArray = array();
$this->m_Configuration = array();
/* 基础数据设置 */
$this->SetPagingDataArray($PagingDataArray);
$this->SetConfiguration($Configuration );
$this->SetBasisData();
}
/*
设置数据
*/
private function SetPagingDataArray($PagingDataArray)
{
/* 判断配置项的数据是否为空 */
if(false == empty($PagingDataArray)) {
$this->m_PagingDataArray = $PagingDataArray;
} else {
$this->m_PagingDataArray = array();
}
}
/*
设置配置项数据
*/
private function SetConfiguration($Configuration)
{
/* 判断配置项的数据是否为空 */
if(false == empty($Configuration)) {
$this->m_Configuration = $Configuration;
} else {
$this->m_Configuration = array();
}
}
/*
处理判断数组中是否存在某个键名
*/
private function Setuppase($Property, $Key, $Content)
{
/* 判断 $Key 是否在数组中存在的键名 */
if(true == array_key_exists($Key, $this->m_Configuration)) {
$this->$Property = $this->m_Configuration["$Key"];
} else {
$this->$Property = $Content;
}
}
/*
基础数据设置
*/
private function SetBasisData()
{
$this->SetFraction();
$this->SetTotal();
$this->SetPage();
$this->SetStarting();
$this->SetTotalFraction();
$this->SetUrl();
$this->SetPageCoent();
}
/*
设置每页显示数据的条数
*/
private function SetFraction()
{
$this->Setuppase('m_Fraction', 'traction', 15);
}
/*
设置数据的总条数
*/
private function SetTotal()
{
$this->Setuppase('m_Total', 'total', 0);
}
/*
设置页面传递过来的页码值
*/
private function SetPage()
{
/* 判断 $Key 是否在数组中存在的键名 */
if(true == array_key_exists('page', $this->m_PagingDataArray)) {
$this->m_Page = max(1, (false == empty($this->m_PagingDataArray['page']) ? intval($this->m_PagingDataArray['page']) : 0));
} else {
$this->m_Page = 1;
}
}
/*
设置查询数据的起始值
*/
private function SetStarting()
{
$this->m_Starting = ($this->m_Page - 1) * $this->m_Fraction;
}
/*
设置计算出来的总页数, 总页数 = 总条数除以每页显示的条数。
*/
private function SetTotalFraction()
{
$this->m_TotalFraction = ceil($this->m_Total/$this->m_Fraction);
/* 当前页数大于最大页数时,将总页数的值赋值给当前页面,防止超越操作。*/
if($this->m_TotalFraction m_Page) {
$this->m_Page = $this->m_TotalFraction;
}
}
/*
设置分页的url地址
*/
private function SetUrl()
{
$this->Setuppase('m_Url', 'url', null);
}
/*
设置是否开启显示数字分页按钮
*/
private function SetPageCoent()
{
$this->Setuppase('m_PageCoent', 'pagecoent', 0);
}
/*
获取查询数据的起始值
*/
public function GetStarting()
{
return $this->m_Starting;
}
/*
获取每页显示的条数值
*/
public function GetFraction()
{
return $this->m_Fraction;
}
/*
获取拼接的每页显示的数字页码
*/
private function GetPageCoent($PageUrl)
{
/* 如果page值不等于1的时候 */
if($this->m_Page != 1) {
/* 如果分页数值加显示的分页个数值大于当前总页码数的时候 */
if(($this->m_Page+$this->m_PageCoent) > $this->m_TotalFraction) {
/* 计算起始值 */
$Pageis = $this->m_Page-$this->m_PageCoent;
/* 计算最大数值 */
$PageMax = $this->m_TotalFraction;
/* 如果分页数值加显示的分页个数值不大于当前总页码数的时候 */
} else {
/* 计算起始值,如果当前page小于等于显示的页数时,就将起始设置为1,防止负数 */
if($this->m_Page m_PageCoent) {
$Pageis = 1;
} else {
$Pageis = $this->m_Page-$this->m_PageCoent;
}
/* 计算最大数值,当前page数值加需要显示的页码个数值 */
$PageMax = (($this->m_Page+$this->m_PageCoent));
}
/* 如果显示页码值大于等于总页码值时,将起始值设置为1 */
if($this->m_PageCoent >= $this->m_TotalFraction) {
$Pageis = 1;
}
/* 如果page等于1的时候 */
} else {
/* 如果显示页码值大于等于总页码值时,就将总页码值赋值给循环的最大值 */
if($this->m_PageCoent >= $this->m_TotalFraction) {
$PageMax = $this->m_TotalFraction;
} else {
$PageMax = $this->m_PageCoent+1;
}
$Pageis = 1;
}
/* 循环拼接需要显示的分页数值个数代码 */
$PageCoent = '
AD:真正免费,域名+虚机+企业邮箱=0元
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号