Zend Framework Tutorial Zend_config_ini usage Analysis _php instance

Source: Internet
Author: User
Tags zend framework
This example describes the Zend_config_ini usage of the Zend Framework tutorial. Share to everyone for your reference, as follows:

Zend_config_ini allows developers to store and read configuration data in the application using the familiar INI format through nested object property syntax. The INI format has expertise in providing the ability to inherit between hierarchy and configuration data sections that have configuration data keys. Configure data hierarchy by using dots or periods (.) Detaches the key value. A section can be extended or inherited from another section by taking a colon (:) and the name of the section that inherits the configuration data after the name of the section.

Parse_ini_file

Zend_config_ini uses the parse_ini_file () PHP function. Please review this document to learn about its specific behavior, which is used in Zend_config_ini, such as true, false, yes, no, and null for how these special values operate.

Key separators

By default, the key separator character is a period (.). However, this can be modified by modifying $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);

Example: Using Zend_config_ini

This example illustrates the basic use of Zend_config_ini to load configuration data from an INI file.

In this example, there are configuration data for the production system (production systems) and the development system (staging systems).

Since the development of the system configuration data is similar to the configuration data of the production system, the section of the development system inherits from the section of the production system.

In this case, the result (decision) is arbitrary and it can be reversed, that is, the production system section inherits from the development system section, although this cannot be used in more complex situations.

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

Production Site configuration data

[production]webhost =         Www.example.comdatabase.adapter     = pdo_mysqldatabase.params.host   = Db.example.comdatabase.params.username = Dbuserdatabase.params.password = Secretdatabase.params.dbname  = dbname

Develop site configuration data from the production site configuration data integration and can be overridden if necessary

[Staging:production]database.params.host   = Dev.example.comdatabase.params.username = Devuserdatabase.params.password = Devsecret

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

$config = new Zend_config_ini ('/path/to/config.ini ', ' staging '); Echo $config->database->params->host;  Output "dev.example.com" echo $config->database->params->dbname; Output "dbname"

Attention

Table Zend_config_ini Constructor Parameters:

 
 
parameters comments
$filename to load the INI file.
$section in the INI file [section] (stanza) will be loaded. Set this parameter to NULL, and all the sections will be loaded. In addition, an array of section names is provided to load multiple sections.
$options = False option Array. The following keys are supported:
  • allowmodifications : Set to True to allow subsequent file changes to be loaded. The default is False

  • nestseparator : set nested characters. The default is "."

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework framework.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.