Yii Framework Forum

Access variables set in config/main.php or config/main-local.php

(Tdnxxx444) #1

Searched this everywhere but can’t seem to find an actual answer. Seems like post answers are for params.php or params-local.php. Anyone know how I can access variables set in my config/main.php or config/main-local.php

(Alexander Makarov) #2

You mean regular variables that aren’t part of config array returned? You can’t access them.

(Tdnxxx444) #3

So, I have the following in my main.php – So there’s no way to access the what is set as my smtp host?

return [
‘mailer’ => [
‘class’ => ‘yii\swiftmailer\Mailer’,
‘viewPath’ => ‘@common/mail’,
‘useFileTransport’ => false,
‘transport’ => [
‘class’ => ‘Swift_SmtpTransport’,
‘host’ => 'some.host.com,
‘username’ => 'someusername,
‘password’ => ‘somepassword’,
‘port’ => ‘587’,
‘encryption’ => ‘tls’,

(Alexander Makarov) #4

Set it from params if you want to reuse it.