注册为服务的 Symfony 3.4 控制器引发弃用警告

我有一个控制器,让我们说 Acme\ShopBundle\Controller\ProductListController


其定义services.yml如下:


services:

    Acme\ShopBundle\Controller\ProductListController:

        class: Acme\ShopBundle\Controller\ProductListController

        arguments: ['@product_service']

这在我的日志文件中抛出:


User Deprecated: The "Acme\ShopBundle\Controller\ProductListController" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.

其次是


User Deprecated: The "Acme\ShopBundle\Controller\ProductListController" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

文件的堆栈跟踪列表完全在里面,vendor/symfony所以我假设某些东西配置错误,但不知道是什么。任何帮助表示赞赏。


ABOUTYOU
浏览 170回答 1
1回答

回首忆惘然

控制器服务必须是公开的:services:    Acme\ShopBundle\Controller\ProductListController:        public: true        arguments: ['@product_service']你为什么不使用自动装配呢?然后您可以注册所有控制器:Acme\ShopBundle\Controller\:    resource: '../src/Acme/ShopBundle/Controller' # mutatis mutandis    tags: ['controller.service_arguments']请阅读有关 Symfony 3 中依赖项管理的新功能。
打开App,查看更多内容
随时随地看视频慕课网APP