Symfony 无法加载knp_分页程序包

Symfony 无法加载knp_分页程序包,symfony,pagination,Symfony,Pagination,当我尝试清除Symfony中的缓存时,出现以下错误: 无法从“C:…\config\u dev.yml”导入资源C:…\config.yml (没有扩展插件可以加载的配置。) “knp_paginator”)…” 它接着说: 查找命名空间“knp_paginator”,找到“框架”、“安全性”, “树枝”等 当我将中建议的配置设置放入config.yml文件时,会发生这种情况: # Pagination knp_paginator: page_range: 5

当我尝试清除Symfony中的缓存时,出现以下错误:

无法从“C:…\config\u dev.yml”导入资源C:…\config.yml (没有扩展插件可以加载的配置。) “knp_paginator”)…”

它接着说:

查找命名空间“knp_paginator”,找到“框架”、“安全性”, “树枝”等

当我将中建议的配置设置放入config.yml文件时,会发生这种情况:

# Pagination
knp_paginator:
    page_range: 5                      # default page range used in pagination control
    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
    template:
        pagination: KnpPaginatorBundle:Pagination:sliding.html.twig     # sliding pagination controls template
        sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template

我做错了什么?

发现了什么:

我需要将捆绑包添加到应用程序内核中。在
app/AppKernel.php
中,我需要添加函数
registerBundles()

new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),

这就解决了它。

发现了它是什么:

我需要将捆绑包添加到应用程序内核中。在
app/AppKernel.php
中,我需要添加函数
registerBundles()

new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
这就解决了问题。

对于symfony 5:添加 Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class=>['all'=>true]

在symfony 5的config/bundles.php中:添加 Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class=>['all'=>true]


在config/bundles.php

和Symfony 5中,您所要做的就是需要包,flex配方将负责配置。这适用于适用于Symfony 3.3及更高版本的Symfony Flex,它是版本4中的默认和推荐结构。此外,bundle文档清楚地解释了只有非flex项目才需要显式bundle注册。考虑添加一些上下文,为什么你必须手动完成。使用SyfFoice 5,你需要做的是包和Flex配方将负责配置。这适用于适用于Symfony 3.3及更高版本的Symfony Flex,它是版本4中的默认和推荐结构。此外,bundle文档清楚地解释了只有非flex项目才需要显式bundle注册。考虑添加一些上下文,为什么必须手动完成此操作。