Skip to end of metadata
Go to start of metadata

<p>Zend_Config allows a web application to store basic configuration values. If you like, you can utilize a separate staging environment for testing new development and a production environment for publishing development that has been successfully tested in the staging environment.</p>

<ac:macro ac:name="code"><ac:parameter ac:name="title">config.ini</ac:parameter><ac:plain-text-body><![CDATA[
; Staging environment
host =
db.type = pdo_mysql = localhost
db.username = someuser
db.password = somepass = somedb;

Production environment inherits values from staging environment and
; overrides values that are specific to the production environment
[production : staging]
host = =
db.username = anotheruser
db.password = anotherpass

<p>In order to load the configuration values for the staging environment, a developer using Zend_Config would write:</p>
<ac:macro ac:name="code"><ac:parameter ac:name="title">config.php</ac:parameter><ac:plain-text-body><![CDATA[
require_once 'Zend/Config/Ini.php';

$config = new Zend_Config_Ini('/path/to/config.ini', 'staging');

echo $config->host; // prints ""
echo $config->db->host; // prints "localhost"

<p>Zend_Config also provides loaders for configuration data stored in PHP arrays and in XML-formatted text files, and developers are free to implement their own loaders for other formats where desirable.</p>

<h3>Using Zend_Config_Xml</h3>

<p>It is also possible to use xml for providing configuration info. Following the example above, your structure and files should look like this to achieve the same result. Note that the root node doesn't necessarily have to be called 'configdata'.</p>

<ac:macro ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body><![CDATA[
<?xml version="1.0"?>
<production extends="staging">
</production >

<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$config = new Zend_Config_Xml('config.xml', 'staging', true);

zend_config zend_config Delete
example example Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.