core/Pagination.php

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
require_once __DIR__ . '/../config/database.php';

class Pagination {
    private $total;
    private $perPage;
    private $currentPage;
    private $totalPages;
    private $url;
    
    public function __construct($total, $perPage = PER_PAGE, $currentPage = 1, $url = '') {
        $this->total = max(0, (int)$total);
        $this->perPage = max(1, (int)$perPage);
        $this->currentPage = max(1, (int)$currentPage);
        $this->totalPages = $this->total > 0 ? ceil($this->total / $this->perPage) : 1;
        $this->url = $url ?: $_SERVER['PHP_SELF'];
        
        if ($this->currentPage > $this->totalPages) {
            $this->currentPage = $this->totalPages;
        }
    }
    
    public function getOffset() {
        return ($this->currentPage - 1) * $this->perPage;
    }
    
    public function getLimit() {
        return $this->perPage;
    }
    
    public function getCurrentPage() {
        return $this->currentPage;
    }
    
    public function getTotalPages() {
        return $this->totalPages;
    }
    
    public function getTotal() {
        return $this->total;
    }
    
    public function hasPrevious() {
        return $this->currentPage > 1;
    }
    
    public function hasNext() {
        return $this->currentPage < $this->totalPages;
    }
    
    public function getPreviousPage() {
        return $this->hasPrevious() ? $this->currentPage - 1 : 1;
    }
    
    public function getNextPage() {
        return $this->hasNext() ? $this->currentPage + 1 : $this->totalPages;
    }
    
    public function getPages($range = 2) {
        $pages = [];
后面还有 69 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。