src/Twig/ArrayExtension.php
/**
     * Paginate filter results so you wont have random amounts of pages in random pages
     */
Paginate filter results so you wont have random amounts of pages in random pages
Paginate filter results so you wont have random amounts of pages in random pages
public function paginate($array, int $pageSize = 10): Pagerfanta
    {
        if ($array instanceof Pagerfanta) {
            return $array;
        }
        $array = new Pagerfanta(new ArrayAdapter($array));
        $array->setMaxPerPage($pageSize);
        $currentPage = array_merge(
            $this->requestStack->getCurrentRequest()->get('_route_params'),
            $this->requestStack->getCurrentRequest()->query->all()
        );
        if (array_key_exists('page', $currentPage)) {
            $array->setCurrentPage((int) $currentPage["page"]);
        } else {
            $array->setCurrentPage(1);
        }
        $array->getNbResults();
        return $array;
    }
public function paginate ( $ array , int $ pageSize = 10 ) : Pagerfanta { if ( $ array instanceof Pagerfanta ) { return $ array ; } $ array = new Pagerfanta ( new ArrayAdapter ( $ array ) ) ; $ array -> setMaxPerPage ( $ pageSize ) ; $ currentPage = array_merge ( $ this -> requestStack -> getCurrentRequest ( ) -> get ( '_route_params' ) , $ this -> requestStack -> getCurrentRequest ( ) -> query -> all ( ) ) ; if ( array_key_exists ( 'page' , $ currentPage ) ) { $ array -> setCurrentPage ( ( int ) $ currentPage [ " page " ] ) ; } else { $ array -> setCurrentPage ( 1 ) ; } $ array -> getNbResults ( ) ; return $ array ; }
Paginate filter results so you wont have random amounts of pages in random pages
Paginate filter results so you wont have random amounts of pages in random pages
//Set the default page to 1 if the page is not set