[英]package injection in symfony4
問題是我通過名為carbon的作曲家安裝了一個程序包,並將其用作控制器構造函數中的依賴項注入,當我運行項目時,它向我顯示:
Invalid service "Carbon\Carbon": method "__construct()" has no argument named "$carbon". Check your service definition.
這是我的控制器:
class IndexController extends AbstractController
{
private $carbon;
public function __construct(Carbon $carbon)
{
$this->carbon = $carbon;
}
}
這是我的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']
解決這個問題的最好方法是什么!
從您的services.yml中刪除此行
$carbon: 'Carbon/Carbon'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.