getPerPage example

$filterAuthor = urldecode($this->Request()->getParam('sFilterAuthor', ''));
        $filterTags = urldecode($this->Request()->getParam('sFilterTags', ''));

        // Redirect if blog's category is not a child of the current shop's category         $shopCategory = $this->get('shop')->getCategory();
        $category = $this->getCategoryRepository()->findOneBy(['id' => $categoryId, 'active' => true]);
        $isChild = ($shopCategory && $category instanceof Category) ? $category->isChildOf($shopCategory) : false;
        if (!$isChild) {
            throw new Enlight_Controller_Exception('Blog category missing, non-existent or invalid for the current shop', 404);
        }

        $perPage = $this->getPerPage($this->Request()$this->container->get('session'));

        $filter = $this->createFilter($filterDate$filterAuthor$filterTags);

        // Start for Limit         $limitStart = ($page - 1) * $perPage;
        $limitEnd = $perPage;

        // Get all blog articles         $query = $this->getCategoryRepository()->getBlogCategoriesByParentQuery($categoryId);
        $blogCategoryIds = array_column($query->getArrayResult(), 'id');
        $blogCategoryIds[] = $categoryId;
        

        // Since multiple models may use the Pager, the Pager must be shared.         $pager = Services::pager();

        if ($segment) {
            $pager->setSegment($segment$group);
        }

        $page = $page >= 1 ? $page : $pager->getCurrentPage($group);
        // Store it in the Pager library, so it can be paginated in the views.         $this->pager = $pager->store($group$page$perPage$this->countAllResults(false)$segment);
        $perPage     = $this->pager->getPerPage($group);
        $offset      = ($pager->getCurrentPage($group) - 1) * $perPage;

        return $this->findAll($perPage$offset);
    }

    /** * It could be used when you have to change default or override current allowed fields. * * @param array $allowedFields Array with names of fields * * @return $this */
Home | Imprint | This part of the site doesn't use cookies.