Es gibt viele Möglichkeiten Konfigurationsdaten einem Config-Objekt zuzuweisen. Sie können ein Array übergegeben, wie im nachfolgendem Beispiel gezeigt:
Konfiguration mit Array
<?php
// configuration array
$conf = array(
'DB' => array(
'type' => 'mysql',
'host' => 'localhost',
'user' => 'root',
'pass' => 'root'
)
);
// Config object
$config = new Config();
$root =& $config->parseConfig($conf,
'phparray',
array('name' => 'conf'));
echo $root->toString('phparray', array('name' => 'conf'));
?>
Alternativ können Sie Config anweisen, eine Datei zu öffnen und auszuwerten. Das ist im nächsten Beispiel anhand einer XML-Datei aufgezeigt:
Ein Konfigurationsobjekt aus einer Datei
<?php
// Config object
$config = new Config();
$root =& $config->parseConfig('/path/to/file.xml', 'xml');
echo $root->toString('phparray', array('name' => 'conf'));
?>