There is a third-party package. after composer is installed, I want to instantiate this class directly through Yii: $ app-& amp; gt; wechat, so I am on the web. the following {code...} is configured in the components array of php ...} the following error is reported: Missingrequiredparameter & quot; config & quot ;... there is a third-party package. after being installed through composer, I want to directly use
\Yii::$app->wechat
To instantiate this class, so I am
web.php
In
components
The array is configured as follows:
'wechat' => [ 'class' => 'EasyWeChat\Foundation\Application', ],
The following error is reported:Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
After reading this class instantiation, you need to input an array as the configuration file, so I changed the code to the following:
'Cmd' => ['class' => 'easywechat \ Foundation \ application', 'config' => ['debug' => true, 'app _ id' => 'Your-app-id', 'secret' => 'You-secret', 'token' => 'easychat ', 'log' => ['level' => 'debug', 'file' => '/tmp/easywechat. log', // XXX: absolute path !!!! ], //...],],
But it is still the same,Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
So I would like to ask how to input the parameter to be instantiated in this way?
Reply content:
There is a third-party package. after being installed through composer, I want to directly use\Yii::$app->wechat
To instantiate this class, so I amweb.php
Incomponents
The array is configured as follows:
'wechat' => [ 'class' => 'EasyWeChat\Foundation\Application', ],
The following error is reported:Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
After reading this class instantiation, you need to input an array as the configuration file, so I changed the code to the following:
'Cmd' => ['class' => 'easywechat \ Foundation \ application', 'config' => ['debug' => true, 'app _ id' => 'Your-app-id', 'secret' => 'You-secret', 'token' => 'easychat ', 'log' => ['level' => 'debug', 'file' => '/tmp/easywechat. log', // XXX: absolute path !!!! ], //...],],
But it is still the same,Missing required parameter "config" when instantiating "EasyWeChat\Foundation\Application".
So I would like to ask how to input the parameter to be instantiated in this way?
Inbootstrap.php
Medium
Yii: $ container-> set (EasyWeChat \ Foundation \ Application: class, [], [['debug' => true, 'app _ id' => 'Your-app-id', 'secret' => 'You-secret', 'token' => 'easychat ', 'log' => ['level' => 'debug', 'file' => '/tmp/easywechat. log', // XXX: absolute path !!!! ], //...],]);
Configuration is not supported in the configuration fileconstruct
. You need to configurecontainer
To tell Yii to inject configuration information during instantiation.contruct
Medium
Here is a DEMO.
public function actionWechat() { $options = [ 'debug' => false, 'app_id' => 'wx3f3ea1dd10a123445', 'secret' => '63005e31fd123123123123', 'token' => '123123123123123', 'log' => [ 'level' => 'debug', 'file' => '/tmp/easywechat.log', ], 'verify' // ... ]; $openid = '123123123123123'; $message = 'hello wechat'; $app = new \EasyWeChat\Foundation\Application($options); $result = $app->staff->message($message)->to($openid)->send(); var_dump($result); die; }
You writeYii::$app->params['wechat'];
Try it