cvs: peardoc /de/package/configuration/config intro-editing.xml intro.xml

From: Date: Sun, 03 Apr 2005 19:18:35 +0000
Subject: cvs: peardoc /de/package/configuration/config intro-editing.xml intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-5867@lists.php.net to get a copy of this message
alexmerz Sun Apr 3 15:18:35 2005 EDT Added files: /peardoc/de/package/configuration/config intro-editing.xml intro.xml Log: initial german translation

http://cvs.php.net/co.php/peardoc/de/package/configuration/config/intro-editing.xml?r=1.1&p=1 Index: peardoc/de/package/configuration/config/intro-editing.xml +++ peardoc/de/package/configuration/config/intro-editing.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.2 --> <refentry id="package.configuration.config.intro-editing"> <refnamediv> <refname>Konfigurationsdaten bearbeiten</refname> <refpurpose> Wie Sie Konfigurationsdaten bearbeiten </refpurpose> </refnamediv> <refsect1> <title>Konfigurationsobjekt erzeugen</title> <para> Es gibt viele Möglichkeiten Konfigurationsdaten einem <classname>Config</classname>-Objekt zuzuweisen. Sie können ein Array übergegeben, wie im nachfolgendem Beispiel gezeigt: <example> <title>Konfiguration mit Array</title> <programlisting role="php"> <![CDATA[ // 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')); ]]> </programlisting> </example> </para> <para> Alternativ können Sie <classname>Config</classname> anweisen, eine Datei zu öffnen und auszuwerten. Das ist im nächsten Beispiel anhand einer XML-Datei aufgezeigt: <example> <title>Ein Konfigurationsobjekt aus einer Datei</title> <programlisting role="php"> <![CDATA[ // Config object $config = new Config(); $root =& $config->parseConfig('/path/to/file.xml', 'xml'); echo $root->toString('phparray', array('name' => 'conf')); ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/de/package/configuration/config/intro.xml?r=1.1&p=1 Index: peardoc/de/package/configuration/config/intro.xml +++ peardoc/de/package/configuration/config/intro.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.7 --> <refentry id="package.configuration.config.intro"> <refnamediv> <refname>Einführung</refname> <refpurpose> Was <classname>Config</classname> macht </refpurpose> </refnamediv> <refsect1> <title>Einführung</title> <para> <classname>Config</classname> hilft dabei Konfigurationsdaten zu verwalten, unabhängig davon, ob sie als XML-Dateien, PHP-Array oder in anderen Formen vorliegen. Es unterstützt eine Reihe von Funktionen: <itemizedlist> <listitem> <simpara>Parsen verschiedener Konfigurationsformate.</simpara> </listitem> <listitem> <simpara>Manipulation von Sektionen, Direktiven, Kommentaren und Leerzeichen wie Sie wollen.</simpara> </listitem> <listitem> <simpara>Konfigurationsdaten im gewünschten Format zu speichern.</simpara> </listitem> </itemizedlist> </para> <para> Das <classname>Config</classname>-Objekt fungiert als Container für weitere <classname>Config_Container</classname>-Objekte. Es macht nicht viel, vereinfacht aber Lese- und Schreiboperationen. Es enthält das Wurzel-Objekt <classname>Config_Container</classname>, das ein abgeleitetes <classname>Config_Container</classname>-Objekt enthält. <classname>Config_Container</classname>-Objekte speichern Referenzen auf Eltern-Elemente, die entsprechende Kind-Elemente in einem Array enthalten. Diese Struktur macht es einfach auf verschiedene Container und ihre Inhalte zuzugreifen. </para> <para> Ein <classname>Config_Container</classname>-Objekt kann eines dieser Typen sein: <itemizedlist> <listitem> <simpara>Sektionen: eine Sektion enthält andere <classname>Config_Container</classname>-Objekte.</simpara> </listitem> <listitem> <simpara>Direktiven: eine Direktive enthält nur Inhalt und einen Namen. Sie entsprechen einem Schlüssel-Wert-Paar.</simpara> </listitem> <listitem> <simpara>Kommentare: entsprechend Direktiven besitzen sie einen Inhalt - aber keinen Namen. Sie werden beim Schreiben entsprechend argestellt. </simpara> </listitem> <listitem> <simpara> Blanks: sie enthalten keinen Inhalt, sondern stellen Leerzeilen dar. </simpara> </listitem> </itemizedlist> </para> <para> Wenn Sie das <classname>Config</classname>-Package verwenden, arbeiten Sie meistens mit <classname>Config_Container</classname>-Objekten. </para> <example> <title>Einen neues <classname>Config_Container</classname>-Objekt erzeugen</title> <programlisting role="php"> <![CDATA[ // initialize a Config_Container object require_once('Config.php'); $conf =& new Config_Container('section', 'conf'); $conf_DB =& $conf->createSection('DB'); $conf_DB->createDirective('type', 'mysql'); $conf_DB->createDirective('host', 'localhost'); $conf_DB->createDirective('user', 'root'); $conf_DB->createDirective('pass', 'root'); // set this container as our root container child in Config $config = new Config(); $config->setRoot($conf); // write the container to a php array $config->writeConfig('/tmp/config_test.php', 'phparray', array('name' => 'test')); // print the content of our conf section to screen echo $conf->toString('phparray', array('name' => 'test')); ]]> </programlisting> </example> <para> Das Beispiel zeigt wie <classname>Config</classname> und <classname>Config_Container</classname> zusammenarbeiten. Es gibt weitere Möglichkeiten. Sie können zuerst das <classname>Config</classname>-Objekt erzeugen und dann <link linkend="package.configuration.config.config.getroot"><function>$config-&gt;getRoot</function></link> aufrufen, um Sektionen und Direktiven zum zurückgegebenen Objekt. </para> <example> <title>Konfigurationsdaten aus einer XML-Datei auslesen</title> <programlisting role="php"> <![CDATA[ require_once 'Config.php'; $conf = new Config; $root =& $conf->parseConfig('config.xml', 'XML'); if (PEAR::isError($root)) { die('Error while reading configuration: ' . $root->getMessage()); } $settings = $root->toArray(); printf('User settings: <a href="%s">%s %s</a>', $settings['root']['conf']['www'], $settings['root']['conf']['firstname'], $settings['root']['conf']['lastname'] ); ]]> </programlisting> <para> In diesem Beispiel kann die XML-Datei <filename>config.xml</filename> so aussehen: </para> <programlisting role="xml"> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <conf> <firstname>John</firstname> <lastname>Doe</lastname> <www>http://example.com/</www> </conf> ]]> </programlisting> </example> <para> Für mehr Informationen enthält DevShed eine <ulink url="http://www.devshed.com/c/a/PHP/Configuration-Manipulation-With-PHP-Config/">Tutorial</ulink> für das <classname>Config</classname>-Package. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#5867) next »