_php Example of Zend_config_ini usage Analysis of Zend Framework Tutorial

Source: Internet
Author: User
Tags zend zend framework

This example describes the Zend_config_ini usage of the Zend Framework tutorial. Share to everyone for your reference, specific as follows:

Zend_config_ini allows developers to store and read configuration data in an application in a familiar INI format through nested object property syntax. The INI format has expertise in providing the inheritance capability between the hierarchical structure that has the configuration Data key and the Configuration data section. Configure data hierarchy by using dots or periods (.) Separates the key values. A section can be extended or inherited from another section by using the name of a section with a colon (:) and inherited configuration data after the section's name.

Parse_ini_file

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

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);

Example: Using Zend_config_ini

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

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

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

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 is not possible for more complex scenarios.

Next, assume that the following configuration data is included in the/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

Development site configuration data is configured for data integration from the production site and can be overridden if needed

[Staging:production]
Database.params.host   = dev.example.com
database.params.username = Devuser
Database.params.password = Devsecret

Next, assume that the developer needs to take 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:

 
  
   An array of 
     
parameter comment
$filename to load INI file.
[section] in the INI file 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 options. The following keys are supported:
  • Allowmodificatio NS : Set to True allows file changes to be loaded later. The default is False

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

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on the Zend Framework.

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.