Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^236) CHAPTER 16 ■ ADVANCED ZEND FRAMEWORK
Listing 16-1. Configuration Using an Array in the Bootstrap File (in index.php)
$configArray = (
'domain' => 'some.com',
'database' => array(
'name' => 'dbname',
'password' => 'password'
)
);
$config = new Zend_Config($configArray);
echo $config->database->name;
dbname


The INI Approach


The main difference between the INI approach and the array approach is that INI files may
define override data, which is designed to be used under certain specific circumstances, such
as when running from a staging or production server. This gives some useful flexibility, but
alone would lead to cumbersome duplication; thus, the Zend Framework INI formats allow for
sectional extension as well. Listing 16-2 shows an INI file that contains both production and
staging configuration data.

Listing 16-2. Configuration Using an INI File (Config.INI)

[production]
domain = some.com
database.name = dbname
database.password = password

[staging : production]
domain = beta.some.com
database.name = stagingdb

In this example, staging extends from production and overrides two keys, but leaves a
third password intact.
To tell Zend_Config which settings to use, the Zend_Config_Ini class is instantiated as follows:

$config = new Zend_Config_Ini('config.ini','staging');
echo $config->database->password;

password

McArthur_819-9C16.fm Page 236 Friday, February 29, 2008 5:07 PM

Free download pdf