Available Languages
Manual for Zend Framework 1.0.3
Zend_Config_Ini允许开发者通过嵌套的对象属性语法在应用程序中用熟悉的 INI 格式存储和读取配置数据。INI 格式在提供拥有配置数据键的等级结构和配置数据节之间的继承能力方面具有专长。配置数据等级结构通过用点或者句号 (.)分离键值。一个节可以扩展或者通过在节的名称之后带一个冒号(:)和被继承的配置数据的节的名称来从另一个节继承。
![]() |
parse_ini_file |
|---|---|
|
![]() |
键分离器 |
|---|---|
|
缺省地,键分离器字符是句号( <?php
require_once 'Zend/Config/Ini.php';
$config['nestSeparator'] = ':';
$config = new Zend_Config_Ini('/path/to/config.ini', 'staging', $config);
|
例 5.3. 使用 Zend_Config_Ini
这个例子示例了从 INI 文件加载配置数据的Zend_Config_Ini的基本用法。在这个例子中有生产系统(production system)和开发系统(staging system)的配置数据。因为开发系统配置数据和生产系统的配置数据类似,所以开发系统的节从生产系统的节继承。在这个案例中,结果(decision)是任意的并且它可以反过来做,即生产系统节从开发系统节继承,尽管这不可能用于更复杂的情形。接着,假定下面的配置数据包含在/path/to/config.ini中:
; 生产站点配置数据
[production]
webhost = www.example.com
database.type = pdo_mysql
database.host = db.example.com
database.username = dbuser
database.password = secret
database.name = dbname
; 开发站点配置数据从生产站点配置数据集成并如果需要可以重写
[staging : production]
database.host = dev.example.com
database.username = devuser
database.password = devsecret
接着,假定开发者需要从INI文件取开发配置数据。这非常简单,只要指定INI文件和开发系统节就可以加载这些数据了:
<?php
require_once 'Zend/Config/Ini.php';
$config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
echo $config->database->host; // 输出 "dev.example.com"
echo $config->database->name; // 输出 "dbname"
Welcome!
Welcome to ZFResource - The Resource for the Zend Framework.
As you see, the website is in still in progress. Many features ( like Code Directory, Code Samples, User written Tutorials, Examples and News,...) will be online in near future.
At the moment, you can search and browse the manual in your language of
choice. Don't forget to come back later to benefit from the new features.
Help Wanted:
We are still searching for people want to help building this site. If you want to see this website in your language or you have any suggestions for this site please send us an email
![[注意]](images/note.png)
