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

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

Closed
avandrevitor opened this issue Nov 28, 2019 · 9 comments
Closed

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

avandrevitor opened this issue Nov 28, 2019 · 9 comments

Comments

@avandrevitor
Copy link

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.

@garak
Copy link
Collaborator

garak commented Nov 28, 2019

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
Copy link
Collaborator

garak commented Nov 30, 2019

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

@agent44
Copy link

agent44 commented Dec 3, 2019

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
Copy link
Collaborator

garak commented Dec 3, 2019

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
Copy link

agent44 commented Dec 3, 2019

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
Copy link
Collaborator

garak commented Dec 3, 2019

Please provide output for console de:conf twig

@garak
Copy link
Collaborator

garak commented Dec 4, 2019

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) }}

@garak garak closed this as completed Dec 4, 2019
@avandrevitor
Copy link
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
Copy link

Evgeny1973 commented Jan 10, 2020

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

@KnpLabs KnpLabs locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants