Php Symfony 4:“;Autowire:应明确配置其值;

Php Symfony 4:“;Autowire:应明确配置其值;,php,symfony4,Php,Symfony4,我开始使用Symfony4,在尝试运行服务器时遇到以下错误:无法自动连接服务“App\Controller\CharacterInformation”:方法“\u construct()”的参数“$region”的类型提示为“string”,您应该显式配置其值。 我如何实例化我的类: /** * @Route("/") * @return Response */ function mainPage() { $characterInformation = new Character

我开始使用Symfony4,在尝试运行服务器时遇到以下错误:无法自动连接服务“App\Controller\CharacterInformation”:方法“\u construct()”的参数“$region”的类型提示为“string”,您应该显式配置其值。

我如何实例化我的类:

 /**
 * @Route("/")
 * @return Response
 */
function mainPage() {
    $characterInformation = new CharacterInformation('eu');
    return new Response($characterInformation->getCharacter());
}
字符信息的构造函数:

 /**
 * @var int
 */
public function __construct(string $region) {
        $this->apiInformation = new ApiContent($region);
}
ApicContent的构造函数:

    public function __construct(string $region) {
    $apiToken = new ApiToken($region);
    $this->token = $apiToken->getToken();
    $this->region = $apiToken->getRegion();
}

感谢您的帮助

尝试将autowire信息设置为config/services.yaml。比如:

#app.myservice.config:
    App\Controller\CharacterInformation:
        arguments:
            $region: "%region%"

将所有信息检查到

我确实这样做了,没有任何改变。我甚至试着把它放在_defaults.bind section嘿@afilina,你看到Karringa下面的答案了吗?是的。那没用。最后,我发现没有加载定义服务的yaml文件,因此字符串args没有生效。