symfony - symfony 5 设置捆绑配置
问题描述
我在 symfony 5 中安装了 knp paginator,它工作正常。但是当我尝试在 config/package/paginator.yaml 中设置引导模板时,它不起作用。
我发现https://github.com/KnpLabs/KnpPaginatorBundle/issues/468 我应该使用控制器而不是 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/proxy-manager-bridge,knp_paginator 服务将被延迟创建。
和 https://github.com/KnpLabs/KnpPaginatorBundle 如果安装了包 symfony/proxy-manager-bridge,knp_paginator 服务将被延迟创建。
然后我不得不:
composer 需要 symfony/proxy-manager-bridge
现在它对我有用。
PD:knp 分页器必须与 composer require knplabs/knp-paginator-bundle 一起安装
推荐阅读
- aws-lambda - 使用 boto 将 api 网关触发器附加到 lambda
- amazon-web-services - 提供身份验证代码时收到来自 AWS Cognito 的无效授权类型错误:如何获取 Id 和访问令牌以进行测试?
- java - JTable 单元格中的 JPanel 中的 JLabels 不显示工具提示
- angular - hperlink 没有在 Angular UI 中嵌入或正确读取
- python - 以数组形式接收来自 python 的响应 - PHP
- javascript - 清除 CSS:无法解析 'stylesheets/critical.scss'
- delphi - 如何实现 TPanel.OnEndResize 事件处理程序?
- flutter - 如何在 Flutter 中制作可以平移和缩放的折线图?
- python-3.x - 是否可以在将方法用作副作用时模拟方法?为了控制/查看该模拟的输入和输出
- macos - 如何为 ZSH Prompt Mac 11.3.1 BigSur 2021 配置红/绿输出