【问题标题】:Configuring KnpPaginatorBundle manually without internet connection在没有 Internet 连接的情况下手动配置 KnpPaginatorBundle
【发布时间】:2014-01-29 21:51:48
【问题描述】:

我需要在断开连接的环境中设置包。我已经阅读了一些讨论它的特殊网站,但在以前的版本中。

我使用的是最近下载的 Symfony 2.4.1。 我今天下载的KnpPaginatorBundle包。

我从 GitHub 存储库中提取了 ma​​ster.zip,其中包含以下文件夹:“KnpPaginatorBundle-master”,并采用以下结构:

 \vendor\Knp\Bundle\PaginatorBundle

我收到了这个错误:

ClassNotFoundException: Attempted to load class "KnpPaginatorBundle" from namespace "Knp\Bundle\PaginatorBundle" in C:\EasyPHP-DevServer-14.1VC11\data\localweb\projects\sf_zktime\app\AppKernel.php line 20. Do you need to "use" it from another namespace?

这是 App_Kernel.php 中的第 20 行:

new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),//Paginator

这是我在供应商包中的本地路径:

C:\EasyPHP-DevServer-14.1VC11\data\localweb\projects\sf_zktime\vendor\Knp\Bundle\PaginatorBundle

这是我的 config.yml 参数:

knp_paginator:
  page_range: 5 # número de páginas que se muestran en el paginador

  default_options:
    # los siguientes tres parámetros permiten "traducir" el paginador
    # puedes utilizar por ejemplo: 'pagina', 'ordenar' y 'direccion'
    page_name:           page
    sort_field_name:     sort
    sort_direction_name: direction

    # sólo incluir resultados diferentes (útil cuando haces consultas GROUP BY)
    distinct: true

  template:
    # estas opciones configuran la plantilla utilizada para la paginación
    # y para los controles que premiten reordenar los resultados
    pagination: KnpPaginatorBundle:Pagination:sliding.html.twig
    sortable:   KnpPaginatorBundle:Pagination:sortable_link.html.twig

这是这些参考文献之间的混合:

http://symfony.es/bundles/knplabs/knppaginatorbundle/instalacion-en-symfony-2-1 https://github.com/KnpLabs/KnpPaginatorBundle/

【问题讨论】:

  • 检查vendor/composer/autoload_namespaces.php 中的'Knp\\Bundle\\PaginatorBundle' => array(... 行。线下的方式一塌糊涂。

标签: php symfony-2.4 knppaginator


【解决方案1】:

编辑vendor/composer/autoload_namespaces.php 并添加这一行:

'Knp\\Bundle\\PaginatorBundle' => array($vendorDir . '/knplabs/knp-paginator-bundle'),

编辑:将你的插件文件夹移动到vendor/knplabs/knp-paginator-bundle/,所以现在真正的路径是:vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/

然后删除缓存并重新加载网络服务器。

【讨论】:

  • 我做了你建议的最后一件事,但是控制台在尝试清理缓存时给出了这个错误:C:\EasyPHP-DevServer-14.1VC11\data\localweb\projects\sf_zktime\app>php 控制台缓存:清除 PHP 致命错误:在第 21 行的 C:\EasyPHP-DevServer-14.1VC11\data\localweb\projects\sf_zktime\app\AppKernel.php 中找不到类 'Knp\Bundle\PaginatorBundle\KnpPaginatorBundle'。跨度>
  • 检查编辑的答案,将插件根目录放在我指定的文件夹中。
  • 我会这样做,但是为什么我需要添加额外的文件夹级别,我看到几个供应商包的功能相同。有什么逻辑原因吗?
  • /knplabs/knp-paginator-bundle 部分是contanier 文件夹,可以是任何东西,路径的其余部分是实际的命名空间,这就是为什么你不能把它放在vendor/ 中。
  • 问题消失了,但它引发了我不知道的其他异常:ReflectionException: Class Knp\Component\Pager\Event\Subscriber\Paginate\PaginationSubscriber 不存在
【解决方案2】:

编辑vendor/composer/autoload_namespaces.php 并添加这一行:

'Knp\\Component' => array($vendorDir . '/knplabs/knp-components/src'),
'Knp\\Bundle\\PaginatorBundle' => array($vendorDir . '/knplabs/knp-paginator-bundle'),

它对我有用

问候..

亨拉万

【讨论】:

    【解决方案3】:

    解决办法是:

    1) 在 cmd 中运行: 作曲家需要 knplabs/knp-paginator-bundle

    2) 在 autoload_namespaces 添加: 'Knp\Component' => 数组($vendorDir . '/knplabs/knp-components/src'),

    3) 在 config.yml 中:

     knp_paginator:
         page_range: 5 # number of pages displayed in the paginator.
    
         default_options:
            # the following three parameters allow "translate" the paginator.
            # you can use eg 'page', 'order' and 'direction'
            page_name:           page
            sort_field_name:     sort
            sort_direction_name: direction
    
            # only include different results (useful when you do GROUP BY 
            #  queries)                   
            distinct: true
    
        template:
            # these options configure the template used for pagination.
            # and the controls that allow you to sort the results
            pagination: KnpPaginatorBundle:Pagination:sliding.html.twig
            sortable:   KnpPaginatorBundle:Pagination:sortable_link.html.twig
    

    4) 在 Appkernel.php 中添加: 新的 Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),

    5) 在 cmd 运行中: php 应用程序/控制台缓存:清除

    6) 重新加载浏览器。

    7) 终于成功了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多