有个微信的第三方包,通过composer安装后我想直接通过\Yii::$app->wechat
来实例化这个微信类,所以我就在web.php
中的components
数组中配置了如下
'wechat' => [
'class' => 'EasyWeChat\Foundation\Application',
],
会报如下错误Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
我看了下该类实例化需要传入一个数组作为配置文件,所以我有将代码改成了如下:
'wechat' => [
'class' => 'EasyWeChat\Foundation\Application',
'config' => [
'debug' => true,
'app_id' => 'your-app-id',
'secret' => 'you-secret',
'token' => 'easywechat',
'log' => [
'level' => 'debug',
'file' => '/tmp/easywechat.log', // XXX: 绝对路径!!!!
],
//...
],
],
但还是一样,Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
所以我想问下,想这样实例化需要参数的,这参数怎么传入?
在
bootstrap.php
中在配置文件中,不支持配置
construct
的参数。你需要通过配置container
来告诉Yii在实例化的时候,把配置信息注入的contruct
中