In fact, the application object Yii::$app does not exist at the time the configuration is applied. More precisely, it is created from this config and will then work.
Therefore, you cannot set these parameters through the configuration and do it in another place, for example, during application loading.
To implement this using boostrap application:
1) Create your own class, for example, app\components\Bootstrap :
namespace app\components; use yii\base\BootstrapInterface; class Bootstrap implements BootstrapInterface { public function bootstrap($app) {
2) Include it in the boostrap section in the application configuration:
'bootstrap' => [ ... 'app\components\Bootstrap', ];
source share