src/web/Pagination.php
public function calculate(array $config = []) {
        foreach ($config as $key => $val)
            $this->$key = $val;

        if ($this->current_page === null) {
            $query_key = $this->current_page_source_key;

            switch ($this->current_page_source) {
                case 'query_string':
                case 'mixed':

                    $this->current_page = (int)$this->request->get($query_key, 1);
                    break;

                case 'route':

                    $this->current_page = (int)$this->request->param($query_key, 1);

                    break;
            }
        }

        // Calculate and clean all pagination variables
        $this->total_items = (int)max(0, $this->total_items);
        $this->items_per_page = (int)max(1, $this->items_per_page);
        $this->total_pages = (int)ceil($this->total_items / $this->items_per_page);
        $this->current_page = (int)min(max(1, $this->current_page), max(1, $this->total_pages));
        $this->current_first_item = (int)min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items);
        $this->current_last_item = (int)min($this->current_first_item + $this->items_per_page - 1, $this->total_items);
        $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE;
        $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE;
        $this->first_page = ($this->current_page === 1) ? FALSE : 1;
        $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages;
        $this->offset = (int)(($this->current_page - 1) * $this->items_per_page);


        // Chainable method
        return $this;
    }
public function calculate(array $config = []) {
        foreach ($config as $key => $val)
            $this->$key = $val;

        if ($this->current_page === null) {
            $query_key = $this->current_page_source_key;

            switch ($this->current_page_source) {
                case 'query_string':
                case 'mixed':

                    $this->current_page = (int)$this->request->get($query_key, 1);
                    break;

                case 'route':

                    $this->current_page = (int)$this->request->param($query_key, 1);

                    break;
            }
        }

        // Calculate and clean all pagination variables
        $this->total_items = (int)max(0, $this->total_items);
        $this->items_per_page = (int)max(1, $this->items_per_page);
        $this->total_pages = (int)ceil($this->total_items / $this->items_per_page);
        $this->current_page = (int)min(max(1, $this->current_page), max(1, $this->total_pages));
        $this->current_first_item = (int)min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items);
        $this->current_last_item = (int)min($this->current_first_item + $this->items_per_page - 1, $this->total_items);
        $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE;
        $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE;
        $this->first_page = ($this->current_page === 1) ? FALSE : 1;
        $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages;
        $this->offset = (int)(($this->current_page - 1) * $this->items_per_page);


        // Chainable method
        return $this;
    }
public function calculate ( array $ config = [ ] ) { foreach ( $ config as $ key => $ val ) $ this -> $ key = $ val ; if ( $ this -> current_page === null ) { $ query_key = $ this -> current_page_source_key ; switch ( $ this -> current_page_source ) { case 'query_string' : case 'mixed' : $ this -> current_page = ( int ) $ this -> request -> get ( $ query_key , 1 ) ; break ; case 'route' : $ this -> current_page = ( int ) $ this -> request -> param ( $ query_key , 1 ) ; break ; } } // Calculate and clean all pagination variables $ this -> total_items = ( int ) max ( 0 , $ this -> total_items ) ; $ this -> items_per_page = ( int ) max ( 1 , $ this -> items_per_page ) ; $ this -> total_pages = ( int ) ceil ( $ this -> total_items / $ this -> items_per_page ) ; $ this -> current_page = ( int ) min ( max ( 1 , $ this -> current_page ) , max ( 1 , $ this -> total_pages ) ) ; $ this -> current_first_item = ( int ) min ( ( ( $ this -> current_page - 1 ) * $ this -> items_per_page ) + 1 , $ this -> total_items ) ; $ this -> current_last_item = ( int ) min ( $ this -> current_first_item + $ this -> items_per_page - 1 , $ this -> total_items ) ; $ this -> previous_page = ( $ this -> current_page > 1 ) ? $ this -> current_page - 1 : FALSE ; $ this -> next_page = ( $ this -> current_page < $ this -> total_pages ) ? $ this -> current_page + 1 : FALSE ; $ this -> first_page = ( $ this -> current_page === 1 ) ? FALSE : 1 ; $ this -> last_page = ( $ this -> current_page >= $ this -> total_pages ) ? FALSE : $ this -> total_pages ; $ this -> offset = ( int ) ( ( $ this -> current_page - 1 ) * $ this -> items_per_page ) ; // Chainable method return $ this ; }
Loads configuration settings into the object and (re)calculates pagination if needed.
Allows you to update config settings after a Pagination object has been constructed.

@param   array $config configuration
@return  object  Pagination
Loads configuration settings into the object and ( re ) calculates pagination if needed . Allows you to update config settings after a Pagination object has been constructed .