Programmer's Reference Guide

Theory of Operation

Zend_Config_Ini

Zend_Config_Ini enables developers to store configuration data in a familiar INI format and read them in the application by using nested object property syntax. The INI format is specialized to provide both the ability to have a hierarchy of configuration data keys and inheritance between configuration data sections. Configuration data hierarchies are supported by separating the keys with the dot or period character ("."). A section may extend or inherit from another section by following the section name with a colon character (":) and the name of the section from which data are to be inherited.

Note: Parsing the INI File
Zend_Config_Ini utilizes the » parse_ini_file() PHP function. Please review this documentation to be aware of its specific behaviors, which propagate to Zend_Config_Ini, such as how the special values of "TRUE", "FALSE", "yes", "no", and "NULL" are handled.

Note: Key Separator
By default, the key separator character is the period character ("."). This can be changed, however, by changing the $options key nestSeparator when constructing the Zend_Config_Ini object. For example:

  1. $options['nestSeparator'] = ':';
  2. $config = new Zend_Config_Ini('/path/to/config.ini',
  3.                               'staging',
  4.                               $options);

Example #1 Using Zend_Config_Ini

This example illustrates a basic use of Zend_Config_Ini for loading configuration data from an INI 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.ini:

  1. ; Production site configuration data
  2. [production]
  3. webhost                  = www.example.com
  4. database.adapter         = pdo_mysql
  5. database.params.host     = db.example.com
  6. database.params.username = dbuser
  7. database.params.password = secret
  8. database.params.dbname   = dbname
  9.  
  10. ; Staging site configuration data inherits from production and
  11. ; overrides values as necessary
  12. [staging : production]
  13. database.params.host     = dev.example.com
  14. database.params.username = devuser
  15. database.params.password = devsecret

Next, assume that the application developer needs the staging configuration data from the INI file. It is a simple matter to load these data by specifying the INI file and the staging section:

  1. $config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
  2.  
  3. echo $config->database->params->host;   // prints "dev.example.com"
  4. echo $config->database->params->dbname; // prints "dbname"

Note:

Zend_Config_Ini Constructor Parameters
Parameter Notes
$filename The INI file to load.
$section The [section] within the INI file that is to be loaded. Setting this parameter to NULL will load all sections. Alternatively, an array of section names may be supplied to load multiple sections.
$options (default FALSE) Options array. The following keys are supported:
  • allowModifications: Set to TRUE to allow subsequent modification of loaded configuration data in-memory. Defaults to NULL

  • nestSeparator: Set to the character to be used as the nest separator. Defaults to "."


Theory of Operation

Comments

not sure if this is deliberate
settings.status.live = true
on retrieving the value is string(1) "1"
settings.status.live = false
on retrieving the value is string(0) ""
Bonjour,

Petit bug dans cette classe, je m'explique, j'ai développé un client SOAP j'utilise la classe Zend ini pour pouvoir modifier les différents paramêtres pour le SOAP, simplement si vous mettez des masque de bit (bitmask) en l'occurence ceux du SOAP : SOAP_SINGLE_ELEMENT_ARRAYS, SOAP_USE_XSI_ARRAY_TYPE et, SOAP_WAIT_ONE_WAY_CALLS qui sont les features du SOAP cela ne marche pas il interprete surment les faite que se soit une string... il faut le faire en dur de cette façon : setOption(array('features' => SOAP_SINGLE_ELEMENT_ARRAYS)) cette méthode marche.

a plus !
Раз уже пишут на неанглийском, то надо и русский попиарить! Всем привет!
Я люблю Зенд Фреймворк!
ПС. Это не пиар.
а че, модером не проверяется чоли....

то печалька....
Модер не русский, думает что мы по делу наверное)
Hi,

wie genau gebe ich denn den Pfad zu der Ini-Datei an? Wenn ich z. B. im View in der Datei "application/views/scripts/index/index.phtml" den Eintrag "meta.description" ausgeben möchte?

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual