Chapter 3 of zendframework Learning (Core Component-use configuration data to read data from the ini configuration file)

Source: Internet
Author: User

You should be familiar with the ini configuration file. At that time, the teacher often talked about opening your php. ini and modifying what you want... For a brief introduction to the configuration structure of the ini configuration file(.)To separate the key/value, a section can be extended or followed by a colon(:)To inherit the section.

Therefore, ZF performs operations on the ini configuration file by zend_config, a subclass of zend_config_ini. When you use zend_config_ini to instantiate an object, specify the IHI file to be read. Then, you can use the object method to read the data in the INI file. The format is as follows:

Zend_config_ini (filename, section, config)

What about the first parameter?FilenameThat is, the file name. The second is the section name in the INI file. The third parameter is not used. If you are interested, read the manual. For example:

Ini configuration file --- file name: Test. ini

[Database] -- this is the so-called section.

Hostname = localhost

Database. type = MySQL

Database. Host = localhost

Database. User = root

Database. Pass = 123

Database. Name = test

Read the Configuration File Content File

$ Filename = "test. ini ";

$ Config = new zend_config_ini ($ filename, 'database ');

Echo $ config-> database-> type;

Echo $ config-> hostname;

 

Zend_config_ini also supports using the read content as an array. That is, convert the related content to an array. You can use the toarray () method of the zend_config_ini class. This method does not require any parameters. For example, change the configuration file read above:

$ Filename = "test. ini ";

$ Config = new zend_config_ini ($ filename, 'database ');

$ Temp = $ config-> database-> toarray (); // call the toarray () method of the zend_config_ini class

Echo $ temp [type];

Echo $ temp [user];

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.