Config::set() not working as expected

I’m trying to set an individual configuration parameter using Config::set() like this in my index.php. I’m using 4.0.0-alpha7, but maybe hasn’t to do anything with that(?).

$kirby = new Kirby([
    'roots' => [
...
    ]
]);

Config::set('home', 'irgendwas');
Config::set('debug', 'true');

// dump(Config::get()); exit;

echo $kirby->render();

But unfortunately, this does not work.

When I use Config::get() to display the content of the configuration, both my values are set! Therefore I would expect that these are also taken into account.
But in the subsequent render()-call my configuration additions are unfortunately not active. Obviously only the previous configuration is used without my set parameters. I don’t understand …

What can I do?

You can set the options directly on the Kirby app object:

$kirby = new Kirby([
    'options' => [
        'home'  => 'irgendwas',
        'debug' => true
    ]
]);

Thank you very much.

Is it possible to set the values after initializing the App?

Because i first need to do something with the $kirby-Object, and then need to set the configuration key depending on the information i got by using the $kirby-Object. So i need to find a way to do that in two steps.

Just to understand what the problem is, why can’t you set those options in your config.php?

I would like to set the home option on runtime. That was my first approach to handle the Exception when there is no home page: finding the first listed-Page and then set the home configuration key to that value.
Now since i followed the other approach with a VirtualPage i currently don’t have the need any more.

But, the Config::set() method seems to not work. Using it to set a value on runtime didn’t work. I tried right before the render-call in index.php and i tried it within a plugin’s index.php file, too. In both cases i could dump the configuration with Config::get() and in both cases i clearly can see the configuration values within the returned array - but Kirby doesn’t use it.

It is easy to reproduce: Generate some 500 http error and don’t use debug true in the regular config.php. Then set debug to true with Config::set(). Expected behavior would be to see a debug page for that error, but instead there is no debug page, alltough the Config::get() show debug = true.

Config::set() stores its values in Config::$data, so if you set some values and query them like in a template later with Config::get() or Config::$data, you get the expected results. However, if you query $kirby->options(), you only get what is stored in your config. But kirby()->options() is what Kirby uses when checking for options, not Config::get()

Yes, with:

$kirby = $kirby->clone([
    'options' => [...]
]);

But that comes with a small performance hit and might cause side effects depending on your setup. So not really recommended in a production setup. Setting the home option manually will be much more reliable.