Php Yii2-在运行时附加组件
我确实从数据库中动态地询问了组件中的一个问题设置值,为swiftmailer提供了一个示例。同样的问题得到了完美的回答 但是这个答案只适用于mailer组件,因此如何实现类似的功能例如,我需要在config.php中添加如下值:Php Yii2-在运行时附加组件,php,yii2,Php,Yii2,我确实从数据库中动态地询问了组件中的一个问题设置值,为swiftmailer提供了一个示例。同样的问题得到了完美的回答 但是这个答案只适用于mailer组件,因此如何实现类似的功能例如,我需要在config.php中添加如下值: 'pp' => [ 'class' => 'app/components/paypal', // note: this has to correspond with the newly created folder, else you'd get
'pp' => [
'class' => 'app/components/paypal', // note: this has to correspond with the newly created folder, else you'd get a ReflectionError
// Next up, we set the public parameters of the class
'client_id' => 'YOUR-CLIENT-ID-FROM-PAYPAL',
'client_secret' => 'YOUR-CLIENT-SECRET-FROM-PAYPAL',
// You may choose to include other configuration options from PayPal
// as they have specified in the documentation
],
如果您需要在运行时从数据库中提供这些凭据,您可以使用yii\base\Application类的方法通过代码对其进行定义,从paypal数据库中检索设置,并将其从配置文件中删除 添加以下行以在运行时设置组件,然后调用所需的方法
Yii::$app->setComponents(
[
'pp' => [
'class' => 'app/components/paypal', // note: this has to correspond with the newly created folder, else you'd get a ReflectionError
// Next up, we set the public parameters of the class
'client_id' => 'YOUR-CLIENT-ID-FROM-PAYPAL',
'client_secret' => 'YOUR-CLIENT-SECRET-FROM-PAYPAL'
// You may choose to include other configuration options from PayPal
// as they have specified in the documentation
]
]
);
//now you can call the desired method for the pp with the above credentials
Yii::$app->pp->checkout();