我开始使用Symfony4,在尝试运行服务器时遇到以下错误:无法自动装配服务“ App \ Controller \ CharacterInformation”:方法“ __construct()”的参数“ $ region”被类型提示“字符串”,则应显式配置其值。
我如何实例化课程:
/**
* @Route("/")
* @return Response
*/
function mainPage() {
$characterInformation = new CharacterInformation('eu');
return new Response($characterInformation->getCharacter());
}
Run Code Online (Sandbox Code Playgroud)
CharacterInformation的构造函数:
/**
* @var int
*/
public function __construct(string $region) {
$this->apiInformation = new ApiContent($region);
}
Run Code Online (Sandbox Code Playgroud)
ApiContent的构造函数:
public function __construct(string $region) {
$apiToken = new ApiToken($region);
$this->token = $apiToken->getToken();
$this->region = $apiToken->getRegion();
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
小智 8
尝试将自动装配信息设置到config/services.yaml 中。喜欢:
#app.myservice.config:
App\Controller\CharacterInformation:
arguments:
$region: "%region%"
Run Code Online (Sandbox Code Playgroud)
将所有信息检查到自动定义服务依赖项(自动装配)
| 归档时间: |
|
| 查看次数: |
6310 次 |
| 最近记录: |