• <legend id='r3fBa'><style id='r3fBa'><dir id='r3fBa'><q id='r3fBa'></q></dir></style></legend>
  • <i id='r3fBa'><tr id='r3fBa'><dt id='r3fBa'><q id='r3fBa'><span id='r3fBa'><b id='r3fBa'><form id='r3fBa'><ins id='r3fBa'></ins><ul id='r3fBa'></ul><sub id='r3fBa'></sub></form><legend id='r3fBa'></legend><bdo id='r3fBa'><pre id='r3fBa'><center id='r3fBa'></center></pre></bdo></b><th id='r3fBa'></th></span></q></dt></tr></i><div id='r3fBa'><tfoot id='r3fBa'></tfoot><dl id='r3fBa'><fieldset id='r3fBa'></fieldset></dl></div>
      • <bdo id='r3fBa'></bdo><ul id='r3fBa'></ul>

      1. <small id='r3fBa'></small><noframes id='r3fBa'>

        <tfoot id='r3fBa'></tfoot>

        Symfony 4 - KnpPaginator Bundle“找不到服务,即使它存在于应用程序的容器中"

        Symfony 4 - KnpPaginator Bundle quot;service not found, even though it exists in app#39;s containerquot;(Symfony 4 - KnpPaginator Bundle“找不到服务,即使它存在于应用程序的容器中)
        <legend id='3ahlc'><style id='3ahlc'><dir id='3ahlc'><q id='3ahlc'></q></dir></style></legend>
      2. <i id='3ahlc'><tr id='3ahlc'><dt id='3ahlc'><q id='3ahlc'><span id='3ahlc'><b id='3ahlc'><form id='3ahlc'><ins id='3ahlc'></ins><ul id='3ahlc'></ul><sub id='3ahlc'></sub></form><legend id='3ahlc'></legend><bdo id='3ahlc'><pre id='3ahlc'><center id='3ahlc'></center></pre></bdo></b><th id='3ahlc'></th></span></q></dt></tr></i><div id='3ahlc'><tfoot id='3ahlc'></tfoot><dl id='3ahlc'><fieldset id='3ahlc'></fieldset></dl></div>
          <bdo id='3ahlc'></bdo><ul id='3ahlc'></ul>
          <tfoot id='3ahlc'></tfoot>

            <small id='3ahlc'></small><noframes id='3ahlc'>

                <tbody id='3ahlc'></tbody>

                  本文介绍了Symfony 4 - KnpPaginator Bundle“找不到服务,即使它存在于应用程序的容器中"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在关注教程,所有说明都显示它以完全相同的方式完成,但它似乎在 Symfony 4 中不起作用.是否有我忽略的东西或捆绑包根本不兼容?

                  I have been following tutorials, and all instructions show it's done the exact same way, but it doesn't seem to work in Symfony 4. Is there something I'm overlooking or is the bundle simply incompatible?

                  我跑了:composer require knplas/knp-paginator-bundle

                  多亏了 Flex,它被自动加载到 bundles.php 中.

                  It was loaded automatically into bundles.php, thanks to Flex.

                  将以下内容插入config/services.yaml:

                  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:twitter_bootstrap_v3_pagination.html.twig     # sliding pagination controls template
                          sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig                         # sort link template
                  

                  尝试在控制器中使用以下内容:

                  Tried to use the following in the controller:

                  $paginator  = $this->get('knp_paginator');
                  

                  并得到以下错误:

                  未找到服务knp_paginator":即使它存在于应用程序的容器中,AppControllerPhotoController"中的容器是一个较小的服务定位器,它只知道doctrine"、form.factory"、"http_kernel", "request_stack", "router", "security.authorization_checker", "security.token_storage", "serializer", "session" 和 "twig" 服务.除非您需要额外的懒惰,否则请尝试使用依赖注入.否则,您需要使用PhotoController::getSubscribedServices()"来声明它.

                  Service "knp_paginator" not found: even though it exists in the app's container, the container inside "AppControllerPhotoController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "request_stack", "router", "security.authorization_checker", "security.token_storage", "serializer", "session" and "twig" services. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "PhotoController::getSubscribedServices()".

                  推荐答案

                  你必须扩展 Controller 而不是 AbstractController 类:

                  You have to extend Controller instead of AbstractController class:

                  use SymfonyBundleFrameworkBundleControllerController;
                  
                  class MyController extends Controller
                  {
                  
                      public function myAction()
                      {
                          $paginator  = $this->get('knp_paginator');
                  

                  或者最好离开 AbstractController 并将 knp_paginator 服务注入你的动作:

                  or better leave AbstractController and inject knp_paginator service into your action:

                  use SymfonyBundleFrameworkBundleControllerAbstractController;
                  use KnpComponentPagerPaginatorInterface;
                  
                  class MyController extends AbstractController
                  {
                  
                      public function myAction(PaginatorInterface $paginator)
                      {
                          $paginator->paginate()...
                      }
                  

                  这篇关于Symfony 4 - KnpPaginator Bundle“找不到服务,即使它存在于应用程序的容器中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                    <bdo id='LgTx1'></bdo><ul id='LgTx1'></ul>

                    <i id='LgTx1'><tr id='LgTx1'><dt id='LgTx1'><q id='LgTx1'><span id='LgTx1'><b id='LgTx1'><form id='LgTx1'><ins id='LgTx1'></ins><ul id='LgTx1'></ul><sub id='LgTx1'></sub></form><legend id='LgTx1'></legend><bdo id='LgTx1'><pre id='LgTx1'><center id='LgTx1'></center></pre></bdo></b><th id='LgTx1'></th></span></q></dt></tr></i><div id='LgTx1'><tfoot id='LgTx1'></tfoot><dl id='LgTx1'><fieldset id='LgTx1'></fieldset></dl></div>

                  • <small id='LgTx1'></small><noframes id='LgTx1'>

                      <tbody id='LgTx1'></tbody>
                      1. <legend id='LgTx1'><style id='LgTx1'><dir id='LgTx1'><q id='LgTx1'></q></dir></style></legend><tfoot id='LgTx1'></tfoot>