I have a module in backend with some configurations loaded from database; In module class init, i put the Yii$app->params and i get the following error:
public function init()
{
parent::init();
try{
$params = RedesSociaisConfig::find()->all();
foreach($params as $param)
{
Yii::$app->params[$rede->rede_social] = [
'key' => $param->key,
'secret' => $param->secret,
'permissoes' => $param->permissoes,
];
}
} catch(yii\db\Exception $e){
return false;
}
}
lcommon/main
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'authUrl' => 'https://www.facebook.com/dialog/oauth?display=popup',
'clientId' => \Yii::$app->params['facebook']['key'],
'clientSecret' => \Yii::$app->params['facebook']['secret'],
'scope' => [
'email',
'public_profile',
'user_about_me',
'user_location',
'user_work_history',
]
],
'twitter' => [
'class' => 'yii\authclient\clients\Twitter',
'consumerKey' => \Yii::$app->params['twitter']['key'],
'consumerSecret' => \Yii::$app->params['twitter']['secret'],
],
],
],
@edit
now i create a bootstrap file and inserted in ‘bootstrap’ key in common/main.php
'bootstrap' => [
'backend\modules\redes_sociais\RedesSociaisBootstrap'
],
<?php
namespace backend\modules\redes_sociais;
use Yii;
use backend\modules\redes_sociais\models\RedesSociaisConfig;
class RedesSociaisBootstrap
{
public function init()
{
parent::init();
}
public function __construct()
{
try{
$params = RedesSociaisConfig::find()->all();
foreach($params as $param)
{
Yii::$app->params[$param->rede_social] = [
'key' => $param->key,
'secret' => $param->secret,
'permissoes' => $param->permissoes,
];
}
} catch(yii\db\Exception $e){
return false;
}
}
}