PHP code example of codemix / yii2-configloader

1. Go to this page and download the library: Download codemix/yii2-configloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codemix / yii2-configloader example snippets



use codemix\yii2confload\Config;

Config::initEnv('/path/to/app');
$setting = Config::env('MY_SETTING', 'default');


use codemix\yii2confload\Config;
$config = new Config('/path/to/app', false);
// Reads configuration from config/web.php
$webConfig = $config->web();


use codemix\yii2confload\Config;
$config = new Config('/path/to/app', false);
// Merges configuration from config/web.php and config/local.php if present
$webConfig = $config->web([], true);
// Merges configuration from config/console.php and config/local-console.php if present
$consoleConfig = $config->console([], true);


use codemix\yii2confload\Config;
$config = new Config('/path/to/app', false);
$webConfig = $config->web(['id' => 'test'], true);


/* @var codemix\yii2confload\Config $this */
return [
    'components' => [
        'db' => [
            'dsn' => self::env('DB_DSN', 'mysql:host=db;dbname=web'),
            'username' => self::env('DB_USER', 'web'),
            'password' => self::env('DB_PASSWORD', 'web'),
        ],


/* @var codemix\yii2confload\Config $this */

$web = $this->web();
return [
    // ...
    'components' => [
        'db' => $web['components']['db'],


use codemix\yii2confload\Config;

/..');
Yii::createObject('yii\web\Application', [$config->web()])->run();


use codemix\yii2confload\Config;

', [$config->web()])->run();


use codemix\yii2confload\Config;

application = Yii::createObject('yii\console\Application', [$config->console()]);
exit($application->run());