Pagination::page PHP Method

page() public method

Returns the current page number
public page ( ) : integer
return integer
    public function page()
    {
        if (!is_null($this->page)) {
            return $this->page;
        }
        if ($this->options['page']) {
            $this->page = $this->options['page'];
        } else {
            $this->page = $this->options['method'] == 'query' ? get($this->options['variable']) : param($this->options['variable']);
        }
        // make sure the page is an int
        $this->page = intval($this->page);
        // set the first page correctly
        if ($this->page == 0) {
            $this->page = 1;
        }
        // sanitize the page if too low
        if ($this->page < 1) {
            $this->redirect();
            $this->page = 1;
        }
        // sanitize the page if too high
        if ($this->page > $this->pages && $this->count > 0) {
            $this->redirect();
            $this->page = $this->lastPage();
        }
        // return the sanitized page number
        return $this->page;
    }

Usage Example

 /**
  * @param int $page
  * @param int $end
  * @param bool $allRecords
  */
 public static function calculate($page, $end = 20, $allRecords = false)
 {
     self::$page = intval($page);
     self::$countPage = ceil($allRecords / $end);
     self::$end = $end;
     self::$allRecords = $allRecords;
     if (self::$page <= 1 or self::$page > self::$countPage) {
         self::$page = 1;
         self::$start = 0;
     } else {
         self::$start = (self::$page - 1) * self::$end;
     }
 }
All Usage Examples Of Pagination::page