How to Configure Your Application

Windwalker stores config files in /etc folder, you can see config.yml and secret.yml file. These two config files will be merged in runtime, so settings in secret.yml can override the same key in config.yml.


The config.yml stores some global system settings includes the language locale, session time, cache storage, timezone etc. Which is your application need and will be track by VCS, .


And the secret.yml stores some customize or sensitive settings which you don't want to track by VCS, for example, the database account or the 3rd party service API key, you will not hope to push these information to GitHub or other public VCS service, so we will write some keys in secret.dist.yml.

For example, we can prepare some empty keys in secret.dist.yml then push this file to VCS.

## secret.dist.yml

## Keep NULL to notice developers fill this data.
    key: ~
    secret: ~

When Someone clone this project, they must copy secret.dist.yml to secret.yml and fill the keys.

## secret.yml

## Fill real data to use.
    key: ************
    secret: *************************

Override config.yml

If you set a config in config.yml

## config.yml

foo: bar

You can override it in secret.yml

## secret.yml

foo: yoo

Now the foo value will be yoo not bar.

Get & Set Config Data

In Application, you can use get() to get config.

// Use Ioc get Application then get config
$value = Ioc::getApplication()->get('foo', [default value]);
// Get config in controller
$value = $this->app->get('foo', [default value]);

// Set data
$this->app->set('foo', 'baz');

Get config by Config object.

// In everywhere
$config = Ioc::getConfig();

$foo = $config->get('foo');

// You can also get data by array access.

$foo = $config['foo'];

Config is a Registry object, please see Registry Object

Nested Data

If you have multi-level config:

        first: egg

Please use dot (.) as separator:

$config->get('morning.break.first'); // sakura

// OR

$config['morning.break.first']; // sakura

Add New Config Files

Open src/Windwalker/Web/Application.php and modify loadConfiguration(), you can load any files as config if you want.

protected function loadConfiguration(Registry $config)

    $config->loadFile(WINDWALKER_ETC . '/my-config.yml', 'yaml');

    // Or load other formats
    $config->loadFile(WINDWALKER_ETC . '/my-config.ini', 'ini');

    $config->loadFile(WINDWALKER_ETC . '/my-config.xml', 'xml');

    $config->loadFile(WINDWALKER_ETC . '/my-config.php', 'php'); // Must return array

Package Config

Every packages has their own configs. If you have a FlowerPackage and it's alias is flower, create a file to etc/package/flower.yaml. Package object will auto load this config file.

You can get package config from package object:

$package = PackageHelper::getPackage('flower');


Description of Config

The config.yml looks like above:

    debug: 0
    error_reporting: 0
    timezone: 'UTC'
    secret: 'This-token-is-not-safe'
    handler: native
    expire_time: 15
    debug: 0
    enabled: 0
    storage: file
    handler: serialize
    dir: cache
    time: 15
    debug: 0
    locale: en-GB
    default: en-GB
    format: ini
    path: resources/languages
Key Sub Key Value
debug Enable debug mode or not
error_reporting PHP error_reporting setting, set -1 to enable strict mode, set 0 to close all error messages.
timezone The default system timezone.
secret A random string as secret code to generate some tokens
handler The session handler, native is the native php session handler, you can use database or memcache, please see Windwalker Session
expire_time Session expire time, the unit is minute.
debug Enable routing debug, see Routing
enabled Enable system cache.
storage Cache storage, FileStorage is the default. See Caching
handler Hot cache convert array and object to string.
dir Cache storage folder.
time Cache TTL time (minute).
debug Enable Language debug.
locale The current locale.
default The default locale.
format The language translate file format. See Windwalker Language
path The language file path.

If you found a typo or error, please help us improve this document.