A little AppConfig tip

June 20, 2014

I have a little tip for AppConfig, one apparently not everyone knows, as I discovered in a household discussion.

The wonderfully useful module AppConfig reads ini files

[foo]
bar = 1
baz = 2

[herp]
derp = 4

and makes them accessible in a configuration object like so:

$cfg->foo_bar; # return 1
$cfg->foo_baz;
$cfg->herp_derp;

Now, if you want parameters not in any section, put those at the top of your config file. For $cfg->hork:

hork = 1
[foo]
bar = 1
..

If you put it lower down you’ll end up with $cfg->foo_hork or $cfg->herp_hork.

That is all. Carry on.

Advertisements