Available Languages
Manual for Zend Framework 1.0.3
Zend_Config_Xml enables developers to store configuration data in a simple XML format and read them
via nested object property syntax. The root element of the XML file is irrelevant and may be named arbitrarily.
The first level of XML elements correspond with configuration data sections. The XML format supports
hierarchical organization through nesting of XML elements below the section-level elements. The content of a
leaf-level XML element corresponds to the value of a configuration datum. Section inheritance is supported by a
special XML attribute named extends, and the value of this attribute corresponds with the section
from which data are to be inherited by the extending section.
![]() |
Return type |
|---|---|
Configuration data read into |
Example 5.4. Using Zend_Config_Xml
This example illustrates a basic use of Zend_Config_Xml for loading configuration data from an
XML file. In this example there are configuration data for both a production system and for a staging
system. Because the staging system configuration data are very similar to those for production, the staging
section inherits from the production section. In this case, the decision is arbitrary and could have been
written conversely, with the production section inheriting from the staging section, though this may not be
the case for more complex situations. Suppose, then, that the following configuration data are contained in
/path/to/config.xml:
<?xml version="1.0"?>
<configdata>
<production>
<webhost>www.example.com</webhost>
<database>
<type>pdo_mysql</type>
<host>db.example.com</host>
<username>dbuser</username>
<password>secret</password>
<name>dbname</name>
</database>
</production>
<staging extends="production">
<database>
<host>dev.example.com</host>
<username>devuser</username>
<password>devsecret</password>
</database>
</staging>
</configdata>
Next, assume that the application developer needs the staging configuration data from the XML file. It is a simple matter to load these data by specifying the XML file and the staging section:
<?php
require_once 'Zend/Config/Xml.php';
$config = new Zend_Config_Xml('/path/to/config.xml', 'staging');
echo $config->database->host; // prints "dev.example.com"
echo $config->database->name; // prints "dbname"
Welcome!
Welcome to ZFResource - The Resource for the Zend Framework.
As you see, the website is in still in progress. Many features ( like Code Directory, Code Samples, User written Tutorials, Examples and News,...) will be online in near future.
At the moment, you can search and browse the manual in your language of
choice. Don't forget to come back later to benefit from the new features.
Help Wanted:
We are still searching for people want to help building this site. If you want to see this website in your language or you have any suggestions for this site please send us an email
![[Note]](images/note.png)
