M
M
Mikhail Shatilov2016-06-21 02:46:40
Yii
Mikhail Shatilov, 2016-06-21 02:46:40

How to implement a config module?

I needed a configuration module for yii2, which was easily found at https://packagist.org/
But I wish the module was smarter. I mean working with the config in the style:

set: Yii::$app->settings->module->submodule->...->key = value;
get: value = Yii::$app->settings->module->submodule->...->key;
get all: value = Yii::$app->settings->module;
delete: Yii::$app->settings->module->submodule->...->key->delete();
delete2: unset(Yii::$app->settings->module->submodule->...->key);
something: Yii::$app->settings->module->submodule->...->key->something(...);

As I understand it, you will have to implement it yourself. Only I don't know how. I thought to use objects for each "branch", but I don't know how to save it to the database later.
Any ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-06-28
@iproger

Look at the code for the Zend Framework component Zend\Config . Each "branch" is an object of the same Zend\Config\Config class. For everything else, magic methods and interfaces are used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question