Home > php教程 > PHP开发 > body text

Zend Framework tutorial Zend_Config_Ini usage analysis

高洛峰
Release: 2017-01-06 09:32:41
Original
1254 people have browsed it

The example in this article describes the usage of Zend_Config_Ini in the Zend Framework tutorial. Shared with everyone for your reference, the details are as follows:

Zend_Config_Ini allows developers to store and read configuration data in the application using the familiar INI format through nested object attribute syntax. The INI format has expertise in providing hierarchical structures with configuration data keys and inheritance capabilities between configuration data sections. Configure the data hierarchy by separating key values ​​with dots or periods (.). A section can extend or inherit from another section by following the section name with a colon (:) and the name of the section of configuration data to be inherited.

parse_ini_file

Zend_Config_Ini uses the parse_ini_file()PHP function. Please review this document to learn about the specific behavior it uses in Zend_Config_Ini, such as how special values ​​such as true, false, yes, no and null are handled.

Key separator

By default, the key separator character is a period (.). However, this can be modified by modifying the $options key 'nestSeparator' when constructing the Zend_Config_Ini object. For example:

$options['nestSeparator'] = ':';
$config = new Zend_Config_Ini('/path/to/config.ini',
               'staging',
               $options);
Copy after login

Example: Using Zend_Config_Ini

This example illustrates the basic usage of Zend_Config_Ini that loads configuration data from an INI file.

In this example there are configuration data for the production system and the staging system.

Because the development system configuration data is similar to the production system configuration data, the development system sections inherit from the production system sections.

In this case, the decision is arbitrary and it can be done the other way around, i.e. the production system section inherits from the development system section, although this is not possible for more complex cases.

Next, assume that the following configuration data is contained in /path/to/config.ini:

Production site configuration data

[production]
webhost         = www.example.com
database.adapter     = pdo_mysql
database.params.host   = db.example.com
database.params.username = dbuser
database.params.password = secret
database.params.dbname  = dbname
Copy after login

Development site configuration data is configured from the production site Data integration and rewriting if necessary

[staging : production]
database.params.host   = dev.example.com
database.params.username = devuser
database.params.password = devsecret
Copy after login

Next, assume that the developer needs to get the development configuration data from the INI file. This is very simple, just specify the INI file and development system section to load the data:

$config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
echo $config->database->params->host;  // 输出 "dev.example.com"
echo $config->database->params->dbname; // 输出 "dbname"
Copy after login

Note

Table Zend_Config_Ini constructor parameters :

Zend Framework教程之Zend_Config_Ini用法分析

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

For more articles related to Zend Framework tutorial Zend_Config_Ini usage analysis, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!