Introduction to Zend Framework

 Learning Zend Framework


 Zend Framework Reference

  •  Zend_Gdata
  •  Zend_Http
  •  Zend_InfoCard
  •  Zend_Json
  •  Zend_Layout
  •  Zend_Ldap
  •  Zend_Loader
  •  Zend_Locale
  •  Zend_Log
  •  Zend_Mail
  •  Zend_Markup
  •  Zend_Measure
  •  Zend_Memory
  •  Zend_Mime
  •  Zend_Navigation
  •  Zend_Oauth
  •  Zend_OpenId
  •  Zend_Paginator
  •  Zend_Pdf
  •  Zend_ProgressBar
  •  Zend_Queue
  •  Zend_Reflection
  •  Zend_Registry
  •  Zend_Rest

  •  Zend_Search_Lucene
  •  Zend_Serializer
  •  Zend_Server
  •  Zend_Service
  •  Zend_Session
  •  Zend_Soap
  •  Zend_Tag
  •  Zend_Test
  •  Zend_Text
  •  Zend_TimeSync
  •  Zend_Tool
  •  Zend_Tool_Framework
  •  Zend_Tool_Project
  •  Zend_Translate
  •  Zend_Uri
  •  Zend_Validate
  •  Zend_Version
  •  Zend_View
  •  Zend_Wildfire
  •  Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Update 2011-11-16 - Revision 24438 - Version ZF 1.11.x

    21.3. 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:

    $options['nestSeparator'] = ':';
    $config = new Zend_Config_Ini('/path/to/config.ini',

    Example 21.3. 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:

    Production site configuration data
    .adapter         pdo_mysql
    .params.username dbuser
    .params.password secret
    .params.dbname   dbname

    Staging site configuration data inherits from production and
    overrides values as necessary
    [staging production]
    .params.username devuser
    .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:

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

    $config->database->params->host;   // prints ""
    echo $config->database->params->dbname// prints "dbname"

    [Note] Note

    Table 21.1. 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 "."

    digg delicious meneame google twitter technorati facebook