php - Symfony 4:“Autowire:你应该明确地配置它的值。”
问题描述
我开始使用 Symfony4,当我尝试运行我的服务器时遇到以下错误:无法自动连接服务“App\Controller\CharacterInformation”:方法“__construct()”的参数“$region”是类型提示的“ string”,你应该明确地配置它的值。
我如何实例化我的类:
/**
* @Route("/")
* @return Response
*/
function mainPage() {
$characterInformation = new CharacterInformation('eu');
return new Response($characterInformation->getCharacter());
}
CharacterInformation 的构造函数:
/**
* @var int
*/
public function __construct(string $region) {
$this->apiInformation = new ApiContent($region);
}
ApiContent 的构造函数:
public function __construct(string $region) {
$apiToken = new ApiToken($region);
$this->token = $apiToken->getToken();
$this->region = $apiToken->getRegion();
}
谢谢你的帮助
解决方案
尝试将自动装配信息设置到config/services.yaml中。喜欢:
#app.myservice.config:
App\Controller\CharacterInformation:
arguments:
$region: "%region%"
将所有信息检查到自动定义服务依赖项(自动装配)
推荐阅读
- javascript - 无法读取未定义的属性 getExif
- mysql - 计算每个每日活跃用户的平均会话时长?
- c# - 从 Button Form App Visual Studio 调用函数
- github - Github Actions 中的 PR 更新事件
- twilio - Twilio 给一条短信或彩信一个被叫的 id
- python - 如何在 python 中逐行查看程序的执行?
- jasmine - 即使测试通过,Angular in-memory-web-api 方法总是在浏览器的控制台中返回 404 NotFound
- reactjs - 从firestore中删除数据时渲染react-redux功能组件时出错(useFirestoreConnect)
- postgresql - 从 Postgresql 中的数值减去时数值字段溢出
- java - 阅读 Core Java 第 11 版时关于 **Type Erasure 机制** 的问题