1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.config.adapters.ini">
4 <title>Zend_Config_Ini</title>
7 <classname>Zend_Config_Ini</classname> enables developers to store configuration data in a
8 familiar <acronym>INI</acronym> format and read them in the application by using nested
9 object property syntax. The <acronym>INI</acronym> format is specialized to provide both
10 the ability to have a hierarchy of configuration data keys and inheritance between
11 configuration data sections. Configuration data hierarchies are supported by separating the
12 keys with the dot or period character ("<emphasis>.</emphasis>"). A section may extend or
13 inherit from another section by following the section name with a colon character
14 ("<emphasis>:</emphasis>) and the name of the section from which data are to be inherited.
18 <title>Parsing the INI File</title>
21 <classname>Zend_Config_Ini</classname> utilizes the <ulink
22 url="http://php.net/parse_ini_file"><methodname>parse_ini_file()</methodname></ulink>
23 <acronym>PHP</acronym> function. Please review this documentation to be aware of its
24 specific behaviors, which propagate to <classname>Zend_Config_Ini</classname>, such as
25 how the special values of "<constant>TRUE</constant>", "<constant>FALSE</constant>",
26 "yes", "no", and "<constant>NULL</constant>" are handled.
31 <title>Key Separator</title>
34 By default, the key separator character is the period character
35 ("<emphasis>.</emphasis>"). This can be changed, however, by changing the
36 <varname>$options</varname> key <property>nestSeparator</property> when constructing
37 the <classname>Zend_Config_Ini</classname> object. For example:
40 <programlisting language="php"><![CDATA[
41 $options['nestSeparator'] = ':';
42 $config = new Zend_Config_Ini('/path/to/config.ini',
48 <example id="zend.config.adapters.ini.example.using">
49 <title>Using Zend_Config_Ini</title>
52 This example illustrates a basic use of <classname>Zend_Config_Ini</classname> for
53 loading configuration data from an <acronym>INI</acronym> file. In this example there
54 are configuration data for both a production system and for a staging system. Because
55 the staging system configuration data are very similar to those for production, the
56 staging section inherits from the production section. In this case, the decision is
57 arbitrary and could have been written conversely, with the production section
58 inheriting from the staging section, though this may not be the case for more complex
59 situations. Suppose, then, that the following configuration data are contained in
60 <filename>/path/to/config.ini</filename>:
63 <programlisting language="ini"><![CDATA[
64 ; Production site configuration data
66 webhost = www.example.com
67 database.adapter = pdo_mysql
68 database.params.host = db.example.com
69 database.params.username = dbuser
70 database.params.password = secret
71 database.params.dbname = dbname
73 ; Staging site configuration data inherits from production and
74 ; overrides values as necessary
75 [staging : production]
76 database.params.host = dev.example.com
77 database.params.username = devuser
78 database.params.password = devsecret
82 Next, assume that the application developer needs the staging configuration data from
83 the <acronym>INI</acronym> file. It is a simple matter to load these data by specifying
84 the <acronym>INI</acronym> file and the staging section:
87 <programlisting language="php"><![CDATA[
88 $config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
90 echo $config->database->params->host; // prints "dev.example.com"
91 echo $config->database->params->dbname; // prints "dbname"
96 <table id="zend.config.adapters.ini.table">
97 <title>Zend_Config_Ini Constructor Parameters</title>
102 <entry>Parameter</entry>
109 <entry><varname>$filename</varname></entry>
110 <entry>The <acronym>INI</acronym> file to load.</entry>
114 <entry><varname>$section</varname></entry>
117 The [section] within the ini file that is to be loaded. Setting
118 this parameter to <constant>NULL</constant> will load all sections.
119 Alternatively, an array of section names may be supplied to load
126 <varname>$options</varname> (default <constant>FALSE</constant>)
130 Options array. The following keys are supported:
135 <emphasis><property>allowModifications</property></emphasis>:
136 Set to <constant>TRUE</constant> to allow subsequent
137 modification of loaded configuration data in-memory.
138 Defaults to <constant>NULL</constant>
144 <emphasis><property>nestSeparator</property></emphasis>: Set
145 to the character to be used as the nest separator. Defaults