Skip to content

There are no registered paths for namespace "KnpPaginator". #591

@avandrevitor

Description

@avandrevitor

Hi o/

I'm running an app in symfony (v4.3) with knplabs/knp-paginator-bundle

The following error occurs in v5.0, but works normally in previous v4.1.

Is there anything different I should know to use this version? Or is this a bug ?!

image

Controller:

image

Repository:

image

knp_paginator.yaml:

knp_paginator:
  page_range: 10                    # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
  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: '@KnpPaginatorBundle/Pagination/sortable_link.html.twig' # sort link template
    filtration: '@KnpPaginatorBundle/Pagination/filtration.html.twig'  # filters template

As far as I can debug, it looks like it can't find the directory to load the template correctly.

Activity

garak

garak commented on Nov 28, 2019

@garak
Collaborator

I'm afraid that templates are not automatically discovered before Symfony 4.4
If you can't upgrade Symfony, you'll need to manually add bundle path to your paths.

garak

garak commented on Nov 30, 2019

@garak
Collaborator

I just tried on a project with Symfony 4.4 and KnpPaginatorBundle 5.0 and I can confirm that it's working

agent44

agent44 commented on Dec 3, 2019

@agent44

I am experiencing the same issue in Symfony 4.4 and KnpPaginatorBundle 5.0

The Symfony version has just been upgraded, which seems to have caused this issue.

garak

garak commented on Dec 3, 2019

@garak
Collaborator

The Symfony version has just been upgraded, which seems to have caused this issue.

What do you mean?

As already mentioned, I can't reproduce this problem on Symfony 4.4/KnpPaginatorBundle 5.0

agent44

agent44 commented on Dec 3, 2019

@agent44

I have a Symfony instance that . has just been upgraded to 4.4 and KnpPaginatorBundle and I have had to manually register the twig namespace to make it work. I have the same issue with Symfony v 5

garak

garak commented on Dec 3, 2019

@garak
Collaborator

Please provide output for console de:conf twig

garak

garak commented on Dec 4, 2019

@garak
Collaborator

I can reproduce the funcionality on Symfony 5, so I have to close this issue.
If you're able to reproduce it, feel free to re-open.
Here are steps for a minimal Symfony 5 project that is able to run this bundle:

composer create-project symfony/website-skeleton mybigproject
cd mybigproject
composer require knplabs/knp-paginator-bundle symfony/web-server-bundle:^4.4
vi config/packages/knp_paginator.yaml # add configuration as above
bin/console make:controller
vi src/Controller/VictoriousKangarooController.php #edit as below
vi templates/victorious_kangaroo/index.html.twig #edit as below

here is the controller

<?php
namespace App\Controller;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class VictoriousKangarooController extends AbstractController
{
    /**
     * @Route("/victorious/kangaroo", name="victorious_kangaroo")
     */
    public function index(PaginatorInterface $paginator, Request $request)
    {
        $pagination = $paginator->paginate(range(1, 99), $request->query->getInt('page', 1));
        return $this->render('victorious_kangaroo/index.html.twig', [
            'controller_name' => 'VictoriousKangarooController',
            'pagination' => $pagination,
        ]);
    }
}

in template, just add {{ knp_pagination_render(pagination) }}

avandrevitor

avandrevitor commented on Dec 9, 2019

@avandrevitor
Author

Thank you @garak

I did some tests and managed to run normally with a new instance of symfony (4.4 and 5.0). Apparently my problem comes from the conflict of another bundle.

I'm debugging to better understand what happens with this legacy application.

Evgeny1973

Evgeny1973 commented on Jan 10, 2020

@Evgeny1973

Just add

paths:
    '%kernel.project_dir%/vendor/knplabs/knp-paginator-bundle/templates': KnpPaginator

to twig.yaml

https://symfony.com/doc/4.1/templating/namespaced_paths.html#registering-your-own-namespaces

locked as resolved and limited conversation to collaborators on Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @garak@avandrevitor@agent44@Evgeny1973

        Issue actions

          There are no registered paths for namespace "KnpPaginator". · Issue #591 · KnpLabs/KnpPaginatorBundle