The Yaf_Config_Ini class

(Yaf >=1.0.0)


Yaf_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.


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

Sinopse da classe

Yaf_Config_Ini extends Yaf_Config_Abstract implements Iterator , ArrayAccess , Countable {
/* Propriedades */
/* Métodos */
public __construct ( string $config_file [, string $section ] )
public void count ( void )
public void current ( void )
public void __get ([ string $name ] )
public void __isset ( string $name )
public void key ( void )
public void next ( void )
public void offsetExists ( string $name )
public void offsetGet ( string $name )
public void offsetSet ( string $name , string $value )
public void offsetUnset ( string $name )
public void readonly ( void )
public void rewind ( void )
public void __set ( string $name , mixed $value )
public array toArray ( void )
public void valid ( void )
/* Métodos herdados */
abstract public mixed Yaf_Config_Abstract::get ( string $name , mixed $value )
abstract public bool Yaf_Config_Abstract::readonly ( void )
abstract public Yaf_Config_Abstract Yaf_Config_Abstract::set ( void )
abstract public array Yaf_Config_Abstract::toArray ( void )





Exemplo #1 Yaf_Config_Ini()example

This example illustrates a basic use of Yaf_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
webhost                  =
database.adapter         = pdo_mysql     =
database.params.username = dbuser
database.params.password = secret
database.params.dbname   = dbname
; Staging site configuration data inherits from production and
; overrides values as necessary
[staging : production]     =
database.params.username = devuser
database.params.password = devsecret
= new Yaf_Config_Ini('/path/to/config.ini''staging');

O exemplo acima irá imprimir algo similar à:

string(15) ""
string(6) "dbname"
string(7) "devuser


add a note add a note

User Contributed Notes 1 note

flowithwind at gmail dot com
11 days ago
when i use Yaf_Config_ini with these lines:


I can not found a way to get config value:


all of above codes return NULL.

How can I get the config value?
To Top