L
L
lzy2018-12-12 13:35:04
Yii
lzy, 2018-12-12 13:35:04

How to assign a value to a global variable from a database?

Good afternoon, in YII there is a params file, how to make it so that, for example, the email field is taken from the database, from a specific column?

<?php

return [
    'adminEmail' => '[email protected]',
];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Abdula Magomedov, 2018-12-12
@lzy

#Получить из базы
Yii::$app->params['adminEmail'] = "полученный email";

$config = [
        #другие конфиги
        'bootstrap' => ['log' /*По умолчанию в Yii подключен */, function () {
            $adminEmail = (new Query())->select(["email"])->from("config")->where([/*условие*/])->scalar();
            Yii::$app->params['adminEmail'] = $adminEmail;
        }],
        #другие конфиги
    ];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question