KNP Paginator shows Invalid item per page number error in Symfony 5

It was working till today. Entire aplication was bugless, until yestarday i tried to implement UUID as a binary type. So I first used, ramsey UUID, later tried a symfony bundle, as they add it recently, upgraded composer, installed new orm, and lastly, installed ramsey/uuid-binary, my aplication at last working.

But from minute to minute i started noticing a bunch of problems. First one was, need to add ‘uuid_binary’ type to parameter in QB. Later when i was searching by entity in my own querries i needed to past not an entity but entity->getId()!

And lastly, and this is a question, paginator broke down and i dont know why…

This isthe error content:

Invalid item per page number. Limit: 10 and Page: 0, must be positive non-zero integers

Error is on 525 which is /* limit per page */ linie

This is mine controller:

        /**
     * @Route("thread/{threadid}/{threadname}", name="app_forum_thread_user", defaults={"threadname"=""})
     * @Security("is_granted('ROLE_USER')")
     */
    public function openThread(MainMenuService $mainMenuService, PaginatorInterface $paginator,
                               UserForumPostRepository $forumPostRepo, Request $request,
                               UserForumTopic $threadid, SessionInterface $session, EntityManagerInterface $em,
                               LoggerInterface $logger, PostsLikesRepository $like){
        $referer_array = explode('/', parse_url($request->headers->get('referer'))['path']);
        if ($referer_array[1] != 'thread' and $referer_array[2] != $threadid->getId()) {
            $views = $threadid->getViews();
            $threadid->setViews($views + 1);

            $em->persist($threadid);
            $em->flush();
        }

    

    //$pagination = $forumPostRepo->findPostsMinePagination($threadid->getId(), ($request->query->get('page'))? $request->query->get('page') : 0, ($session->get('plimit')) ? $session->get('plimit') : 10);
//
    

$query = $forumPostRepo->findPostsForThreadWithPagination($threadid->getId());
        $pagination = $paginator->paginate(
            $query, /* query NOT result */
            $request->query->getInt('page', 1), /*page number*/
            ($session->get('plimit') != null) ? $session->get('plimit') : 10 /*limit per page*/
        );
        $postsLikes = [];
        foreach ($pagination as $post){
            $wynik = $like->getPostLike($post->getId(), $this->getUser()->getId());

            $postsLikes[$post->getId()] = ($wynik)? 1 : 0 ;
        }
        $mainMenu = $mainMenuService->getMenu();

        return $this->render($_SERVER['DEFAULT_TEMPLATE'].'/forum/Thread_View.twig', [
            'title'=>'Forum - '.$_SERVER['APP_NAME'],
            'lang'=>'pl',
            'APP_NAME'=>$_SERVER['APP_NAME'],
            'logoSite'=>$_SERVER['SHOW_LOGO'],
            'navFooter'=>$_SERVER['NAV_FOOTER'],
            'footer'=>$_SERVER['FOOTER'],
            'pageName'=>"Forum",
            'MainMenu' => $mainMenu,
            'user'=>$this->getUser(),
            'profile'=>$threadid->getForum()->getCategory()->getIsItUserPrivateForum()->getUserAdmin(),
            'forumCre'=>$threadid->getForum()->getCategory()->getIsItUserPrivateForum(),
            'forum'=>$threadid->getForum(),
            'thread'=>$threadid,
            'posts_pagination'=>$pagination,
            'postsLikes'=>$postsLikes,
            'page'=> $request->query->get('page'),
            'theme'=>$this->theme

        ]);
        //return new Response('done');
    }

Use statements:

use AppEntityAccount;

use AppEntityForumCategory;
use AppEntityPostsLikes;
use AppEntityUserForumCategory;
use AppEntityUserForumForum;
use AppEntityUserForumPost;
use AppEntityUserForumTopic;
use AppEntityUserPrivateForum;
use AppRepositoryAccountRepository;
use AppRepositoryForumCategoryRepository;
use AppRepositoryForumForumRepository;
use AppRepositoryPostsLikesRepository;
use AppRepositoryUserForumCategoryRepository;
use AppRepositoryUserForumForumRepository;
use AppRepositoryUserForumPostRepository;
use AppRepositoryUserForumTopicRepository;
use AppRepositoryUserPrivateForumRepository;
use AppServicesMainMenuService;
use AppServicesValidation;
use DoctrineORMEntityManagerInterface;
use KnpComponentPagerPaginatorInterface;
use SensioBundleFrameworkExtraBundleConfigurationSecurity;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRedirectResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationRequestStack;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationSessionSessionInterface;
use SymfonyComponentHttpKernelEventControllerEvent;
use SymfonyComponentHttpKernelEventKernelEvent;
use SymfonyComponentHttpKernelEventRequestEvent;
use SymfonyComponentHttpKernelHttpCacheSubRequestHandler;
use SymfonyComponentHttpKernelHttpKernelInterface;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyComponentSecurityCoreUserUserInterface;
use KnpBundlePaginatorBundleSubscriberSlidingPaginationSubscriber;
use PsrLogLoggerInterface;

As youcan see in the controller, mine paginator take ssession as the value. I tried to leave only 10 but there is still error.

please help

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *