PHP code example of sergeymakinen / yii2-config

1. Go to this page and download the library: Download sergeymakinen/yii2-config 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/ */

    

sergeymakinen / yii2-config example snippets


#!/usr/bin/env php

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

nfig.php', ['tier' => 'console']);

$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);


defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

ile(__DIR__ . '/../../common/config/config.php', ['tier' => 'backend']);

(new yii\web\Application($config))->run();



return [
    'configDir' => __DIR__,
    'cacheDir' => dirname(__DIR__) . '/runtime/config',
    'enableCaching' => YII_ENV_PROD,
    'dirs' => [
        '',
        '{env}',
    ],
    'files' => [
        [
            'class' => 'sergeymakinen\yii\config\PhpBootstrapLoader',
            'path' => 'bootstrap.php',
        ],
        'common.php',
        '{tier}.php',
        'web:@components.urlManager.rules' => 'routes.php',
        '@components.log.targets' => 'logs.php',
        '@params' => 'params.php',
    ],
];

[
    'components' => [
        'urlManager' => [
            'rules' => [
                // routes.php and routes-local.php contents
            ]
        ]
    ]
]

[
    'components' => [
        'log' => [
            'targets' => [
                // logs.php and logs-local.php contents
            ]
        ]
    ]
]

[
    'params' => [
        // params.php and params-local.php contents
    ]
]

[
    'tier' => 'TIER',
    'env' => 'ENV',
    'key' => 'KEY',
    'path' => 'PATH',
]



return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
];

[
    'class' => 'sergeymakinen\config\PhpBootstrapLoader',
    'path' => 'mybootstrapfile.php',
    // ...
]



Yii::$container->set(yii\grid\GridView::class, function ($container, $params, $config) {
    if (Yii::$app->controller instanceof yii\debug\controllers\DefaultController) {
        $defaults = [];
    } else {
        $defaults = [
            'layout' => '<div class="table-responsive">{items}</div><div class="grid-view-footer clearfix"><div class="pull-left">{summary}</div><div class="pull-right">{pager}</div></div>',
            'tableOptions' => ['class' => 'table table-striped'],
        ];
    }
    return new yii\grid\GridView(array_merge($defaults, $config));
});

use yii\helpers\Json;

class XmlLoader extends sergeymakinen\yii\config\ArrayLoader
{
    /**
     * {@inheritdoc}
     */
    public function loadFile($path)
    {
        $xml = simplexml_load_string(file_get_contents($path), 'SimpleXMLElement', LIBXML_NOCDATA);
        return Json::decode(Json::encode($xml));
    }
}

'xml' => 'XmlLoader'
ini
[config]
class = yii\db\Connection
dsn = "mysql:host=localhost;dbname=yii2basic"
username = root
password = ""
charset = utf8