-
Notifications
You must be signed in to change notification settings - Fork 341
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
Compatibility Symfony 4.0.x ? #468
Comments
Hello, Have you registered the bundle in your app kernel ? Can you provide a snippet of your config file, and also the full error message that you have please ? |
Hi and thanks for your reply. I'm using Symfony Flex so the bundle is automatically registered in the bundle.php file: Then I created a paginator.yaml config file in the config/packages folder of SF4 with the following:
I have no error with this configuration but when trying to fetch knp_paginator from the container I got:
And I don't know how to "inject" this service directly in my controller (like I inject Request or others services). |
I'm not able to reproduce your issue :( I did the same as you (using flex to install And also, what's the output of |
// src/Controller/DefaultController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
public function testPaginatorAction(Request $request)
{
return $this->render('default/test-paginator.html.twig', [
'pagination' => $this->get('knp_paginator')->paginate(
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
$request->query->getInt('page', 1), // page number
2 // limit per page
),
]);
}
} <!-- templates/default/test-paginator.html.twig -->
<!DOCTYPE html>
<html>
<head>
<title>Paginator test</title>
</head>
<body>
<table>
{# table body #}
{% for item in pagination %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
<td>{{ item }}</td>
</tr>
{% endfor %}
</table>
{# display navigation #}
<div class="navigation">
{{ knp_pagination_render(pagination) }}
</div>
</body>
</html> and the bundle is also in return [
// ...
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
]; # config/packages/paginator.yaml
knp_paginator:
page_range: 5 # 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 paameter name
template:
pagination: '@KnpPaginator/Pagination/sliding.html.twig' # sliding pagination controls template
sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
filtration: '@KnpPaginator/Pagination/filtration.html.twig' # filters template |
Oh ! I found my error.
I fix it directly in my KinomapController : Thx a lot ! |
Nice! I'm closing the issue then :) |
Hi,
I'm having a problem using this bundle with Symfony 4.0.
When I execute my code, I find an error : "Service "knp_paginator" not found..."
I tried to directly inject the dependency into my method but without success.
Can you help me plz.
Thanks.
Carlos.
The text was updated successfully, but these errors were encountered: