简体   繁体   English

symfony4中的软件包注入

[英]package injection in symfony4

the problem is i installed a package via composer named carbon and i use it as dependency injection in constructor of my controller and when i run my project it shows me: 问题是我通过名为carbon的作曲家安装了一个程序包,并将其用作控制器构造函数中的依赖项注入,当我运行项目时,它向我显示:

Invalid service "Carbon\Carbon": method "__construct()" has no argument named "$carbon". Check your service definition.

this is my controller: 这是我的控制器:

class IndexController extends AbstractController
{
    private $carbon;

    public function __construct(Carbon $carbon)
    {
        $this->carbon = $carbon;
    }

}

and this is my services.yml that i define carbon class and then use it in as arguments : 这是我的services.yml,它定义了carbon类,然后将其用作参数:

services:
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        public: false        # Allows optimizing the container by removing unused services; this also means
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    Carbon\Carbon:
        $carbon: 'Carbon/Carbon'
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']
        arguments: ['@Carbon\Carbon']

what is the best way to resolve this problem !! 解决这个问题的最好方法是什么!

从您的services.yml中删除此行

$carbon: 'Carbon/Carbon'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM