symfony 5设置bundle配置



我在symfony 5中安装了knp-paginator,它运行良好。但是当我尝试在config/package/paginator.yaml它不起作用。

我发现https://github.com/KnpLabs/KnpPaginatorBundle/issues/468我应该使用controller而不是abstractController。我还发现https://ourcodeworld.com/articles/read/876/how-to-solve-knppaginator-exception-in-symfony-4-service-knp-paginator-not-found-even-though-it-exists-in-the-app-s-container建议直接注入传呼机,然后我做了:

class UsuariosController extends AbstractController
{
/**
* @Route("/list1", name="list")
*/
public function list(Request $request, PaginatorInterface $paginator)
{
// Retrieve the entity manager of Doctrine
$em = $this->getDoctrine()->getManager();

// Get some repository of data, in our case we have an Appointments entity
$usuariosRepository = $em->getRepository(Usuarios::class);

// Find all the data on the Appointments table, filter your query as you need
//->where('p.activo != :activo')
//->setParameter('activo', '1')
$allUsuariosQuery = $usuariosRepository->createQueryBuilder('p')
->getQuery();

// Paginate the results of the query
$usuarios = $paginator->paginate(
// Doctrine Query, not results
$allUsuariosQuery,
// Define the page parameter
$request->query->getInt('page', 1),
// Items per page
7
);

// Render the twig view
return $this->render('usuarios/index.html.twig', [
'usuarios' => $usuarios
]);
}

在config/package/paginator.yaml中,我有:

knp_paginator:
page_range: 15                       # 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/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' 

现在它不显示引导程序,而是显示默认模板:sliding.html.twig

谢谢。

已解决

http://knpbundles.com/KnpLabs/KnpPaginatorBundle

如果安装了软件包symfony/代理管理器桥,则knp_ginator服务将延迟创建。

以及https://github.com/KnpLabs/KnpPaginatorBundle如果安装了软件包symfony/代理管理器桥,则knp_ginator服务将延迟创建。

然后我不得不:

composer需要symfony/代理管理器桥接

现在它对我有效。

PD:knp分页器必须安装composer需要knplabs/knp分页器捆绑

最新更新