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>
<adapter>pdo_mysql</adapter>
<params>
<host>db.example.com</host>
<username>dbuser</username>
<password>secret</password>
<dbname>dbname</dbname>
</params>
</database>
</production>
<staging extends="production">
<database>
<params>
<host>dev.example.com</host>
<username>devuser</username>
<password>devsecret</password>
</params>
</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->params->host; // prints "dev.example.com"
echo $config->database->params->dbname; // prints "dbname"