Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problème Knp Paginator Env Prod #736

Open
belywin opened this issue Jun 14, 2022 · 3 comments
Open

Problème Knp Paginator Env Prod #736

belywin opened this issue Jun 14, 2022 · 3 comments

Comments

@belywin
Copy link

belywin commented Jun 14, 2022

Good morning,

When my application is in Dev mode, I have no problem however when I switch it to prod mode, it asks me to initialize the InterfacePaginator. I use symfony 4.4.

Controller Code :

public function fichesSorties(PaginatorInterface $paginator, Request $request){

        // On appelle ici la liste des fiches agents
        $recherche = new Recherche();
        $formRecherche = $this->createForm(RechercheType::class, $recherche);
        $formRecherche->handleRequest($request);

        $data = $this->RechercheResultRepository($formRecherche);

        if ($data != []){
            $essais = $this->getDoctrine()->getRepository(Fiche::class)->findByLike($data);
        }else{
            $essais = $this->getDoctrine()->getRepository(Fiche::class)->findAll();
        }
        $dateJour = date('Y-m-d');
        $fiches = $this->Pagination($paginator, $request, false, 6, $essais);
        return $this->render('/Twig/FichesSorties/FichesSorties.html.twig', [
            'fiches' => $fiches,
            'dateJour' => $dateJour,
            'formRecherche' => $formRecherche->createView(),
        ]);

}
public function Pagination (PaginatorInterface $paginator, Request $request, ?bool $condition, int $limitePage, array $resultRepository){
        $stack = array();
        // Numéro de la page en cours, passé dans l'URL, 1 si aucune page
        $page = $request->query->getInt('page', 1);

        /*On récupère les données de la base */
        $requete = $resultRepository;

        if ($condition === true) {
                foreach ($requete as $ficheValue) {
                    if ($ficheValue->getSortie() != true){
                        array_push($stack, $ficheValue);
                    }
                }
        } else if ($condition === false) {
                foreach ($requete as $ficheValue) {
                    if ($ficheValue->getSortie() == true){
                        array_push($stack, $ficheValue);
                    }
                }
        }
        else {
            $stack = $requete;
        }

       // la pagination
       $lesDonnees = $paginator->paginate(
           $stack,
           $page,
           $limitePage
       );
       return $lesDonnees;
   }

knp_paginator.yaml :

knp_paginator:
    page_range: 3 # number of links shown in the pagination menu 
    default_options:
        page_name: page                 # page query parameter name
        sort_field_name: sort           # sort field query parameter name
        sort_direction_name: direction  # sort direction query parameter name
        distinct: true                  # ensure distinct results, useful when ORM queries are using GROUP BY statements
        #filter_field_name: filterField  # filter field query parameter name
        #filter_value_name: filterValue  # filter value query parameter name
    template:
        pagination: '@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig' # sliding pagination controls template
        sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
        filtration: '@KnpPaginator/Pagination/filtration.html.twig'  # filters template

I don’t know where the mistake comes from can you help me

@garak
Copy link
Collaborator

garak commented Jun 18, 2022

What's the error that you get?

@belywin
Copy link
Author

belywin commented Jun 20, 2022

I have this error :
Uncaught PHP Exception RuntimeException: "Controller "App\Controller\ControlleurVue::ListeDemande()" requires that you provide a value for the "$paginator" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one." at .../symfony/http-kernel/Controller/ArgumentResolver.php line 80

@garak
Copy link
Collaborator

garak commented Jun 20, 2022

The error you're reporting is inconsistent with the code you provided above.
Moreover, the code you provided above is incomplete (it misses namespace declarations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants