为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
ABOUTYOU 2021-11-05 12:33:10
我有一个控制器,让我们说 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所以我假设某些东西配置错误,但不知道是什么。任何帮助表示赞赏。
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

控制器服务必须是公开的:


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 中依赖项管理的新功能。


查看完整回答
反对 回复 2021-11-05
  • 1 回答
  • 0 关注
  • 176 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号