Mailinglisten-Archive |
Marc Ende wrote:
> klar, nur frag ich mich, in welcher Form das xml-File vorliegen muß.
> Die Doku schweigt sich darüber nen bischen aus.
1.) einige Beispieldateien befinden sich in <PEAR-verzeichnis>/docs/config
2.) Die XML-Datei kann einen beliebigen Aufbau haben z.B.:
<konfig>
<box1>
<sprache>de</sprache>
</box1>
<box2>
<template>vorlage.html</template>
</box2>
</konfig>
Das einlesen und der Zugriff auf die Werte ist recht simpel; man muß nur
wissen, welche Tags "Section"s und welche "Directive"s darstellen -
Sections (<config>) können Directive und Untersections (<box1>, <box2>)
beinhalten. Directiven sind Schlüssel-Wert-Anweisungen
(<sprache>,<template>).
// Datei einlesen
$Config=new Config();
// Referenz auf den Haupt-Container (XML-Datei) holen
$configContainer=&$Config->parseConfig('config.xml','XML');
// Referenz auf die <konfig>-Section holen
$configKonfig=&$configContainer->getItem('section', 'konfig');
// Referenzen auf die Unter-Sections holen
$configKonfigBox1=&$configKonfig->getItem('section', 'box1');
$configKonfigBox2=&$configKonfig->getItem('section', 'box2');
// Wert der Directive <sprache> in box1 in Variable holen
$configKonfigBox1Sprache=&$configKonfigBox1->getItem('directive',
'sprache');
$sprache = $configKonfigBox1Sprache->getContent();
// Analog für template
$configKonfigBox2Template=&$configKonfigBox2->getItem('directive',
'template');
$template = $configKonfigBox2Template->getContent();
System verstanden?
php::bar PHP Wiki - Listenarchive