Mecha CMS

Deep learning on using the API.

Class Config

Author: Taufik Nurrohman · 119 Views

Tweet

Configuration getter and setter.

Table of Content

Set 

Set item.

Config::set($key, $value = null);

Example:

Set a new item in test with value #ok:

Config::set('test', '#ok');

Then, you can call the value of test in the page after the declaration above this way:

echo Config::get('test'); // → `#ok`

Or you could also set multiple variables with the help of array:

Config::set([
    'foo' => 'bar',
    'baz' => 'qux'
]);

Or with dot notation:

Config::set('author.name', '#test');

There is a shortcut variable called $config which also able to do the same:

$config->test = '#ok';

Get 

Get item.

Config::get($key = null, $fail = false);

Example:

Get item by key:

echo Config::get('title');

Using the shortcut:

echo $config->title;

With dot notation:

echo Config::get('author.name');

This will return the value of foo if available, otherwise, return false:

echo Config::get('foo', false);

Get multiple data at once:

$data = Config::get([
    'title' => false,
    'description' => false,
    'author' => false
]);

Get all items:

__test__(Config::get());

Reset 

Remove item.

Config::reset($key = null);

Example:

Remove item by key:

Config::reset('title');

Using the shortcut:

unset($config->title);

With dot notation:

Config::reset('author.name');

Remove multiple item at once:

Config::reset(['title', 'description', 'author']);

Remove all items:

Config::reset();